True DBGrid for WinForms | ComponentOne
Customization / Captions, Headers, and Footers
In This Topic
    Captions, Headers, and Footers
    In This Topic

    Affix a title to a grid, column, or split by setting the Caption property of the appropriate object.

    For example, the following code sets captions on a grid, column, and split:

    C#
    Copy Code
    //Grid caption
    this.c1TrueDBGrid1.Caption = "Grid Caption";
    this.c1TrueDBGrid1.Columns[0].Caption = "Column 0 Caption";
    this.c1TrueDBGrid1.Splits[0].Caption = "Split 0 Caption";
    

    Column and Grid Captions

    For C1DataColumn objects, the Caption property specifies the text that appears in each column's header area. If using True DBGrid for WinForms controls bound to a DataSet, the column captions are set automatically at run time.

    Column captions can also be set in the designer using the C1TrueDBGrid Designer, or in code by manipulating the C1DataColumnCollection.

    The Caption property also applies to the C1TrueDBGrid control itself, which provides a descriptive header for the entire grid.

    By default, C1TrueDBGrid displays headings for each column; even the Caption property of an individual column is never set explicitly. However, all column headings can be hidden by setting the ColumnHeaders property to False.

    Column Footers

    Just as the ColumnHeaders property controls the display of column captions, the ColumnFooters property controls the display of the column footer row. Column footers, which are similar in appearance to column headers, are always displayed at the bottom of the grid, even if it is under populated.

    For each C1DataColumn object, the FooterText property determines the text that is displayed within the footer row. Set the footer text in the designer using the C1TrueDBGrid Designer, or in code by manipulating the C1DataColumnCollection collection, as in the following example:

    C#
    Copy Code
    this.c1TrueDBGrid1.ColumnFooters = true;
    this.c1TrueDBGrid1.Columns[0].FooterText = "Footer 0";
    this.c1TrueDBGrid1.Columns[1].FooterText = "Footer 1";
    

    Unlike the Caption property, the FooterText property is not set automatically from a bound data source, so you will have to set it yourself.

    Multiple-Line Headers and Footers

    The split specific property ColumnCaptionHeight property controls the height of the column headers. By default, it is based upon the font setting of the HeadingStyle. To display more than one line of text in a column header, increase the ColumnCaptionHeight property to accommodate additional lines, as in the following example:

    C#
    Copy Code
    this.c1TrueDBGrid1.Splits[0].ColumnCaptionHeight = this.c1TrueDBGrid1.Splits[0].ColumnCaptionHeight * 2;
    this.c1TrueDBGrid1.Columns[0].Caption = "First line\nSecond line";
    

    Note the use of the "\n" to specify a line break within the caption text. After this code executes, the first column's caption will contain two lines of text, and the second column's caption will be centered vertically.

    Similarly, set the ColumnFooterHeight property to control the height of column footers, and use the constant to specify a line break when setting the FooterText property of a column.

    Split Captions

    Split objects can also have their own captions. For a grid with one split, a split caption can serve as a second grid caption.

    However, split captions are best used in grids with at least two splits, as they are ideal for categorizing groups of columns for end users.