ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

C1TrueDBGrid.UnboundColumnFetch Event

Occurs when the grid needs to access the value of an unbound column.

[Visual Basic]

Public Event UnboundColumnFetch As UnboundColumnFetchEventHandler

[C#]

public event UnboundColumnFetchEventHandler UnboundColumnFetch

[Delphi]

public property UnboundColumnFetch: UnboundColumnFetchEventHandler read remove_UnboundColumnFetch write add_UnboundColumnFetch;

Remarks

For a bound grid, any column with an empty C1DataColumn.DataField property and a non-empty C1DataColumn.Caption property is considered an unbound column.

To return an unbound value to the grid, simply set the UnboundColumnFetchEventArgs.Value property to the desired result. If a value is not assigned, the cell will remain blank.

Use this event to implement calculated fields based on other columns or to display local data alongside remote bound data.

The application is responsible for storing data entered into an unbound column by the user. Use the C1DataColumn object's C1DataColumn.Text property to retrieve unbound values within the BeforeUpdate and BeforeInsert events.

If an unbound column is used to display a calculated result based on other columns, then the unbound values do not need to be stored since they can always be calculated "on the fly" using either the C1DataColumn object's C1DataColumn.Text property or data access objects.

Note: During the execution of this event, row movement is not permitted.

Example

The following code code uses dtCopy, a global DataTable, to gather values to place into the unbound column, then sets these values equal to e.Value, placing the value into an unbound column:

·      Visual Basic

       Dim dtCopy As New DataTable

       Private Sub C1TrueDBGrid1_UnboundColumnFetch(ByVal sender As System.Object, ByVal e As C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs) Handles C1TrueDBGrid1.UnboundColumnFetch

           Dim row As Integer = e.Row

           If Me.C1TrueDBGrid1.FocusedSplit.Rows(e.Row).RowType = C1.Win.C1TrueDBGrid.RowTypeEnum.DataRow Then

               row = Me.C1TrueDBGrid1.RowBookmark(e.Row)

           End If

           If e.Col = 0 And e.Row < dtCopy.Rows.Count Then

               e.Value = dtCopy.Rows(e.Row).Item("FirstName") & " " & dtCopy.Rows(e.Row).Item("LastName")

           End If

       End Sub

·      C#

       DataTable dtCopy = new DataTable;

       private void c1TrueDBGrid1_UnboundColumnFetch( System.object sender, C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs e)

       {

           int row = e.Row;

           if(this.c1TrueDBGrid1.FocusedSplit.Rows[e.Row].RowType == C1.Win.C1TrueDBGrid.RowTypeEnum.DataRow)

           {

                  row = this.c1TrueDBGrid1.RowBookmark(e.Row);

           }

           if ( e.Col == 0 & e.Row < dtCopy.Rows.Count )

           {

               e.value = dtCopy.Rows[e.Row].["FirstName"] + " " + dtCopy.Rows[e.Row] ["LastName"];

           }

       }

·      Delphi

       var dtCopy: DataTable;

         dtCopy := DataTable.Create;

       procedure TWinForm.c1TrueDBGrid1_UnboundColumnFetch(sender: System.Object; e: C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs);

       var

         row : Integer;

       begin 

         row := e.Row;

         if (Self.C1TrueDBGrid1.FocusedSplit.Rows[e.Row].RowType = C1.Win.C1TrueDBGrid.RowTypeEnum.DataRow) then

           row := Self.C1TrueDBGrid1.RowBookmark(e.Row);

         if((e.Col = 0) and (e.Row < dtCopy.Rows.Count)) then

           e.Value := dtCopy.Rows[e.Row]['FirstName'].ToString + ' ' + dtCopy.Rows[e.Row]['LastName'].ToString;

       end;

See Tutorial 6 - Defining Unbound Columns in a Bound Grid for the complete example.

See Also

C1TrueDBGrid Class | C1TrueDBGrid Members | C1.Win.C1TrueDBGrid Namespace


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.