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:
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
· C#
C1.Win.C1TrueDBGrid.C1DataColumn Col = new 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);
· Delphi
var
Col1: C1TrueDBGrid.C1DataColumn;
dc: C1.Win.C1TrueDBGrid.C1DisplayColumn;
begin
with Self.C1TrueDBGrid1 do
begin
Columns.Insert(0, Col1);
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;
end;
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.
Private Sub C1TrueDBGrid1_UnboundColumnFetch(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs) Handles C1TrueDBGrid1.UnboundColumnFetch
· C#
private void C1TrueDBGrid1_UnboundColumnFetch(object sender, C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs e)
· Delphi
procedure C1TrueDBGrid1_UnboundColumnFetch(sender: System.Object; e: C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs);
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |