ComponentOne True DBGrid for WinForms
Creating Unbound Columns
Data Binding > Using Unbound Columns > Creating Unbound Columns

The first step in using an unbound column is creating the column itself. This may be done in the designer by adding a column through the C1TrueDBGrid Designer. In code, unbound columns may be added using the Insert method of the C1DataColumnCollection. The column must be given a name by setting its Caption property. In the designer, this is done using the C1TrueDBGrid Designer. In code, the Caption property of the appropriate C1DataColumn object is set. C1DataColumn objects that are added to the C1DataColumnCollection cause a corresponding C1DisplayColumn to be added to the C1DisplayColumnCollection for all splits. The default visible property of the newly added C1DisplayColumn will be False.

When attempting to insert an unbound column in code, use the Rebind method to ensure that the column appears at the desired position within the grid:

To write code in Visual Basic

Visual Basic
Copy Code
Dim Col As New C1.Win.C1TrueDBGrid.C1DataColumn
Dim dc As C1.Win.C1TrueDBGrid.C1DisplayColumn
 
With Me.C1TrueDBGrid1
    .Columns.Insert(0, Col)
    Col.Caption = "Unbound"
    dc = .Splits(0).DisplayColumns.Item("Unbound")
 
    ' Move the newly added column to leftmost position in the grid.
    .Splits(0).DisplayColumns.RemoveAt(.Splits(0).DisplayColumns.IndexOf(dc))
    .Splits(0).DisplayColumns.Insert(0, dc)
    dc.Visible = True
    .Rebind(True)
End With

To write code in C#

C#
Copy Code
C1.Win.C1TrueDBGrid.C1DataColumn Col = new C1.Win.C1TrueDBGrid.C1DataColumn();
C1.Win.C1TrueDBGrid.C1DisplayColumn dc;
c1TrueDBGrid1.Columns.Insert(0, Col);
Col.Caption = "Unbound";
dc = c1TrueDBGrid1.Splits[0].DisplayColumns["Unbound"];
 
// 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(0, dc);
dc.Visible = true;
c1TrueDBGrid1.Rebind(true);

When the grid needs to display the value of an unbound column, it fires the UnboundColumnFetch event. This event supplies the user with a row and column index as the means of identifying the grid cell being requested. The Value property to the event is of type Object that by default is Null, but can be changed to any desired value, and will be used to fill the contents of the cell specified by the given row and column index.

To write code in Visual Basic

Visual Basic
Copy Code
Private Sub C1TrueDBGrid1_UnboundColumnFetch(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs) Handles C1TrueDBGrid1.UnboundColumnFetch

To write code in C#

C#
Copy Code
private void c1TrueDBGrid1_UnboundColumnFetch(object sender, C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs e)
See Also