Calculate total grid height, different using different themes

1 Answer 65 Views
GridView Themes and Visual Style Builder
Jure
Top achievements
Rank 2
Iron
Iron
Iron
Jure asked on 01 Oct 2023, 10:02 AM

Hi,

I have a grid within a panel and I want to adjust the panel height based on the total height of the grid.

Using this code:


Me.Panel1.Height = Me.grid.TableElement.RowHeight * Me.grid.RowCount + grid.TableElement.TableHeaderHeight + 5

 

It seems to work ok if I use "Fluent" theme but not for "VisualStudio2012Light". I have attached a sample form.

Any explanation for this and how do I fix it?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Oct 2023, 11:53 AM

Hi, Jure,

I have added the provided form files in a brand new project to test the grid's sizing on my end. Note that if you want to size the panel according to the height of the grid, you can set the RadGridView.AutoSize property to true. Thus, the grid control will be sized according to the required space for the rows. Once a new theme is applied, the grid will be resized accordingly. Then, you can set the panel's Height property to the RadGridView.Height property:

Me.grid.AutoSize = True
Me.Panel1.Height = Me.grid.Height

The achieved result is illustrated below:

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Jure
Top achievements
Rank 2
Iron
Iron
Iron
commented on 05 Oct 2023, 10:30 AM

Hi Dess,

sure that works yes, but in the real project I'm using several grids/panels with potentially thousands of rows and AutoSize slows things down significantly. That's why I wanted to use RowCount*RowHeight...

Dess | Tech Support Engineer, Principal
Telerik team
commented on 10 Oct 2023, 09:13 AM

Hi, Jure, 

Indeed, if you have more rows than you can see in the view, auto sizing the rows is not suitable. Using the calculation RowCount*RowHeight will give you the height that is needed for the data rows. This wouldn't include the column header row, the new row and the filtering row if it is enabled. That is why they also should be included to the calculation. The following article is useful for specifying the height for the different row types in the grid: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/resizing-rows 

    Public Sub New()

        InitializeComponent()


        Me.grid.AutoSize = False
        Me.grid.EnableGrouping = False
        Me.grid.ShowGroupPanelScrollbars = True
        Me.grid.AllowSearchRow = True
        Me.grid.TableElement.SearchRowHeight = 50
        Me.grid.MasterView.TableAddNewRow.Height = 40
        Me.grid.TableElement.TableHeaderHeight = 60
        Me.grid.EnableFiltering = True
        Me.grid.TableElement.FilterRowHeight = 50
    End Sub

    Private Sub AdjustGridHeight()
        Dim totalHeight = Me.grid.TableElement.RowHeight * Me.grid.RowCount
        If Me.grid.ShowColumnHeaders Then
            totalHeight = totalHeight + grid.TableElement.TableHeaderHeight
        End If
        If Me.grid.AllowAddNewRow Then
            totalHeight = totalHeight + grid.MasterView.TableAddNewRow.Height
        End If
        If Me.grid.AllowSearchRow Then
            totalHeight = totalHeight + grid.TableElement.SearchRowHeight
        End If
        If Me.grid.ShowGroupPanel Then
            totalHeight = totalHeight + grid.GridViewElement.GroupPanelElement.Size.Height

        End If
        If grid.EnableFiltering Then
            totalHeight = totalHeight + grid.TableElement.FilterRowHeight
        End If
        Me.Panel1.Height = totalHeight + 5
    End Sub

Tags
GridView Themes and Visual Style Builder
Asked by
Jure
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or