This is a migrated thread and some comments may be shown as answers.

Set the row height to fill all grid space?

3 Answers 173 Views
GridView
This is a migrated thread and some comments may be shown as answers.
awt
Top achievements
Rank 1
awt asked on 11 Jul 2016, 08:33 AM
I am trying to set the row height of the RadGridView element to fill the whole space of the grid instead of showing blank space when the number of rows is less than the height of the grid, the problem is I couldn't find a simple way to do this without many complications and performance issues using different events to set the RowHeight property when the size is changed for the grid. How to achieve this?

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Jul 2016, 10:16 AM
Hello Abdulwadood,

Thank you for writing. 

RadGridView controls the rows size by the TableElement.RowHeight property. In order to fill the entire grid with the data rows, you can manage the RowHeight property by handling the RadGridView.SizeChanged event. Here is demonstrated a sample approach:
 
public Form1()
{
    InitializeComponent();
    this.radGridView1.Columns.Add("Col 1");
    for (int i = 0; i < 5; i++)
    {
        this.radGridView1.Rows.Add("Row" + i);
    }
 
    this.radGridView1.SizeChanged += radGridView1_SizeChanged;
    this.radGridView1.TableElement.ViewInfo.TableAddNewRow.Height = 20;
}
 
private void radGridView1_SizeChanged(object sender, EventArgs e)
{
    RecalculateRowHeight();
}
 
private void RecalculateRowHeight()
{
    int headerHeight = this.radGridView1.TableElement.TableHeaderHeight;
    int filterHeight = this.radGridView1.TableElement.FilterRowHeight;
    int newRowHeight = this.radGridView1.TableElement.ViewInfo.TableAddNewRow.Height;
  
    this.radGridView1.TableElement.RowHeight =
        Math.Max(1, (this.radGridView1.Height - (headerHeight + filterHeight + newRowHeight)) / this.radGridView1.Rows.Count);
}
 
private void Form1_Load(object sender, EventArgs e)
{
    RecalculateRowHeight();
}

I hope this information helps. Should you have further questions I would be glad to help.

 Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
awt
Top achievements
Rank 1
answered on 12 Jul 2016, 01:31 PM

Thank you very much for your reply.

I am getting a compilation error (RadGridView does not contain a definition for TableElement...). There is only an object called TableDefinition. 

I am using Telerik.Windows.Controls.GridView assembly.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Jul 2016, 02:01 PM
Hello Abdulwadood,

Thank you for writing back. 

I would like to note that this forum is related to the Telerik UI for WinForms product. However, your question seems to be related to the WPF suite. Feel free to post your technical question in the relevant forum: http://www.telerik.com/forums

Thank you for your understanding.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
awt
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
awt
Top achievements
Rank 1
Share this question
or