So far, our examples have demonstrated the UnboundColumnFetch event using only a single unbound column. Suppose you want to have more than one? Since the UnboundColumnFetch event 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 argument, Col, is used to identify the column of the list 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.DsRectangle1.Tables(0).Copy() End Sub Private Sub C1List1_UnboundColumnFetch(ByVal sender As System.Object, ByVal e As C1.Win.C1List.UnboundColumnFetchEventArgs) Handles C1List1.UnboundColumnFetch Select Case Me.C1List1.Columns(e.Col).Caption Case "Area" ' Calculate the "Area" column of the list. e.Value = dtCopy.Rows(e.Row).Item("Length") * dtCopy.Rows(e.Row).Item("Width") Case "Perimeter" ' Calculate the "Perimeter" column of the list. 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.DsRectangle1.Tables[0].Copy(); } private void C1List1_UnboundColumnFetch(System.object sender, C1.Win.C1List.UnboundColumnFetchEventArgs e) { switch (this.c1List1.Columns[e.Col].Caption) { case "Area": // Calculate the "Area" column of the list. e.Value = dtCopy.Rows[e.Row]["Length"] * dtCopy.Rows[e.Row]["Width"]; break; case "Perimeter": // Calculate the "Perimeter" column of the list. e.Value = 2 * (dtCopy.Rows[e.Row][ "Length"] + dtCopy.Rows[e.Row]["Width"]); break; } } |