Find by ID:
Go
[Log in | Register]
Home
Support Center Home
Categories (Beta)
Report Issue
Report a Bug
Make a Suggestion
Ask a Question
Security
Log in
Register
Forgot Password
Support Center Stats

Issue Reports
Total: 43360
Active: 398
Processed: 42962

Suggestions
Total: 17801
Active: 506
Processed: 17295

Questions
Total: 98464
Active: 94
Processed: 98370

1851 Knowledge Base Articles

557 Code Central Examples

Powered by Developer Express AJAX-Enabled ASP.NET components

This website is powered by Developer Express ASP.NET technologies including the ASPxMenu, ASPxNavBar, ASPxTabControl, ASPxSiteMapControl, ASPxPopupControl and the ASPxGridView and Editors Suite.
Database connectivity is via eXpressPersistent Objects.

Knowledge Base Article

How to change the Grid's height according to the total height of its rows

Article ID: A2825
Product Group: .NET
Product: XtraGrid Suite
Version(s): 3, 6
Updated: 20 Mar 2009
Categories: n/a

Description

Is it possible to change the Grid's height so that only its rows are visible in the content area and there is no empty space.

Solution

Unfortunately, there is no easy way to achieve this task. However, you can implement it using reflections. Please see the sample below:

[C#]

using System.Reflection;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Scrolling;
......................
            Type type = gridView1.GetType();
            FieldInfo fi = type.GetField("fViewInfo", BindingFlags.NonPublic | BindingFlags.Instance);
            GridViewInfo info = fi.GetValue(gridView1) as GridViewInfo;
            fi = type.GetField("fScrollInfo", BindingFlags.NonPublic | BindingFlags.Instance);
            ScrollInfo scrollInfo = fi.GetValue(gridView1) as ScrollInfo;
            int height = info.CalcRealViewHeight(new Rectangle(0, 0, Int32.MaxValue, Int32.MaxValue));
            if (scrollInfo.HScrollVisible)
                height += scrollInfo.HScrollRect.Height;
            gridControl1.Height = height;

[VB.NET]

Imports System.Reflection
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Scrolling
........................
        Dim type As Type = GridView1.GetType()
        Dim fi As FieldInfo = type.GetField("fViewInfo", BindingFlags.NonPublic Or BindingFlags.Instance)
        Dim info As GridViewInfo = CType(fi.GetValue(GridView1), GridViewInfo)
        fi = type.GetField("fScrollInfo", BindingFlags.NonPublic Or BindingFlags.Instance)
        Dim scrollInfo As ScrollInfo = CType(fi.GetValue(GridView1), ScrollInfo)
        Dim height As Integer = info.CalcRealViewHeight(New Rectangle(0, 0, Int32.MaxValue, Int32.MaxValue))
        If (scrollInfo.HScrollVisible) Then
            height += scrollInfo.HScrollRect.Height
        End If
        GridControl1.Height = height

Note:
Since version 6.1 the name of the "fScrollInfo" private member (in the line "fi = type.GetField("fScrollInfo"...")has been changed to "scrollInfo".
Also, you can get the GridViewInfo object without reflection using the following code:

[C#]

GridViewInfo info = gridView1.GetViewInfo() as GridViewInfo;

[VB.NET]

Dim info As GridViewInfo = CType(GridView1.GetViewInfo(), GridViewInfo)




Do you have any comments? We are eager to hear them!

How would you rate the quality of this content?

Average rating: 6.75 out of 9
4 people have rated this page
 
 
 
1
2
3
4
5
6
7
8
9
 
Post Your Vote (Login Required)
If you need any clarification with regards to the contents of this article, please don't hesitate to contact our Support Team.