ComponentOne True DBGrid for WinForms
Data Binding / Using Unbound Columns / Implementing Multiple Unbound Columns
In This Topic
    Implementing Multiple Unbound Columns
    In This Topic

    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.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    ' 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
    

    To write code in C#

    C#
    Copy Code
    // 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;
               }
    }
    
    See Also