True DBGrid for WinForms | ComponentOne
Rows / Sizing
In This Topic
    Sizing
    In This Topic

    True DBGrid lets you manipulate the size of grid rows, such as set the row height and auto-adjust the row height.

    Set Row Height

    True DBGrid provides the RowHeight property of Frame class to set row height across the grid. You can also specify the height of a particular row by setting Height property of the Row class. Default value of the Height property is -1 which indicates that the row is taking height specified by the DefaultSize property.

    Use the code below to set the default height of a row of the WinForms True DBGrid.

    C#
    Copy Code
    // Setting height of the all the rows
    c1TruedbGrid1.RowHeight = 30;
    

    But if you have to set a particular row's width, use the code snippet below:

    C#
    Copy Code
    //setting a Row's height
    var row = c1TruedbGrid1.Splits[0].Rows[1];
    row.Height = 60;
    

    The True DBGrid control also lets you decide whether all the rows should have the same height or different heights using the RowSizingEnum enumeration.

    C#
    Copy Code
    //if it is AllRows, all rows will have same height
    c1TruedbGrid1.AllowRowSizing = RowSizingEnum.AllRows;
    //if it is IndividualRows , rows can have separate heights
    c1TruedbGrid1.AllowRowSizing = RowSizingEnum.IndividualRows;
    

    Auto-adjust Row Height

    To adjust the row height, you can simply use the AutoSize method.

    C#
    Copy Code
    //call autosize for each row
    foreach (ViewRow row in c1TruedbGrid1.Splits[0].Rows) {
        row.AutoSize();
    }