True DBGrid for WinForms | ComponentOne
Columns / Basic Operations
In This Topic
    Basic Operations
    In This Topic

    This topic discusses about the various basic operations that can be performed on a column in True DBGrid.

    Insert Column

    True DBGrid lets you add a new column at the specified index using the Insert method of C1DataColumnCollection class.

    C#
    Copy Code
    C1.Win.TrueDBGrid.C1DataColumn Col = new C1.Win.TrueDBGrid.C1DataColumn();
    C1.Win.TrueDBGrid.C1DisplayColumn dc;
    c1TruedbGrid1.Columns.Insert(0, Col);
    var colName = "Unbound" + c1TruedbGrid1.Columns.Count;
    Col.Caption = colName;
    dc = c1TruedbGrid1.Splits[0].DisplayColumns[colName];
    // Move the newly added column to leftmost position in the grid.
    c1TruedbGrid1.Splits[0].DisplayColumns.RemoveAt(c1TruedbGrid1.Splits[0].DisplayColumns.IndexOf(dc));
    c1TruedbGrid1.Splits[0].DisplayColumns.Insert(c1TruedbGrid1.Col, dc);
    dc.Visible = true;
    c1TruedbGrid1.Rebind(true);
    

    Delete Column

    To delete a particular column from the grid, you can use the RemoveAt method of the C1DataColumnCollection class

    C#
    Copy Code
    if (c1TruedbGrid1.Columns.Count > 0)
        c1TruedbGrid1.Columns.RemoveAt(c1TruedbGrid1.Col);
    

    Set Data Type

    True DBGrid lets you set the data type of an unbound column in WinForms True DBGrid using the DataType property of the C1DataColumn class as shown in the code below.

    C#
    Copy Code
    // Set datatype of a column [only works in Unbound mode]
    c1TruedbGrid1.Columns[0].DataType = typeof(string);
    

    Set Frozen Column

    Frozen columns, similar to fixed columns, are non-scrollable but can be edited by the user. In True DBGrid, frozen columns can be set by using Frozen property provided by the C1DisplayColumn class.

    To set frozen columns in the WinForms True DBGrid, use the code below.

    C#
    Copy Code
    this.c1TruedbGrid1.Splits[0].DisplayColumns[1].Frozen = true;