ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Implementing Multiple Unbound Columns

So far, our examples have demonstrated the UnboundColumnFetch event using only a single unbound column but more than one unbound column can be used. Since the UnboundColumnFetch is fired for each unbound column of each row, only one column value may be set at a time, and each column must be identified for the value to be properly determined. The second UnboundColumnFetch property, Column, is used to identify the column of the grid for which the value is required.

·      Visual Basic

' Will be used as the copy.

Dim dtCopy As Data.DataTable

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

           dtCopy = Me.DataSet11.Tables(0).Copy()

End Sub

 

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

           Select Case e.Column.Caption

        Case "Area"

 

                   ' Calculate the "Area" column of the grid.

                   e.Value = dtCopy.Rows(e.Row).Item("Length") * dtCopy.Rows(e.Row).Item("Width")

        Case "Perimeter"

 

                   ' Calculate the "Perimeter" column of the grid.

                   e.Value = 2 * (dtCopy.Rows(e.Row).Item("Length") + dtCopy.Rows(e.Row).Item("Width"))

           End Select

End Sub

·      C#

// Will be used as the copy.

Data.DataTable dtCopy;

 

private void Form1_Load( System.object sender,  System.EventArgs e)

{

    dtCopy = this.DataSet11.Tables[0].Copy();

}

 

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

{

           switch (e.Column.Caption;)

    {

        case "Area";

 

                   // Calculate the "Area" column of the grid.

                   e.value = dtCopy.Rows[e.Row].Item["Length"] * dtCopy.Rows(e.Row).Item("Width");

            break;

        case "Perimeter";

 

            // Calculate the "Perimeter" column of the grid.

                   e.value = 2 * (dtCopy.Rows[e.Row].Item["Length"] + dtCopy.Rows[e.Row].Item["Width"]);

            break;

           }

}

·      Delphi

// Will be used as the copy.

var dtCopy: System.Data.DataTable; 

 

procedure TWinForm.Form1_Load(sender: System.Object; e: System.EventArgs);

begin

  dtCopy := Self.DataSet11DsContacts1.Tables[0].Copy;

end;

 

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

var s: string;

begin

  s := Self.C1TrueDBGrid1.Columns[e.Col].Caption;

  if (s = 'Area') then

 

    // Calculate the "Area" column of the grid.

    e.Value := dtCopy.Rows[e.Row].Item['Length'] *

        dtCopy.Rows[e.Row].Item['Width'];

  else if (s = 'Perimeter') then 

 

    // Calculate the "Perimeter" column of the grid.

    e.Value := 2 * (dtCopy.Rows[e.Row].Item['Length'] +

        dtCopy.Rows[e.Row].Item['Width']);

end;


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