Set the row height to fill all grid space?

4 posts, 0 answers
  1. awt
    awt avatar
    5 posts
    Member since:
    Jul 2016

    Posted 11 Jul Link to this post

    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?
  2. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 12 Jul Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. awt
    awt avatar
    5 posts
    Member since:
    Jul 2016

    Posted 12 Jul Link to this post

    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.

  5. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 12 Jul Link to this post

    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.
Back to Top