In this tutorial, you will learn how to use the UnboundColumnFetch event to display two fields (FirstName and LastName) together in one column. You will also learn how to use an SQL statement to create a join between two tables in a database.
Complete the following steps:
SELECT Customers.FirstName, Customers.LastName, Customers.CustType, Contacts.ContactType, Contacts.Callback, Contacts.ContactDate, Contacts.UserCode, Customers.UserCode AS Expr1 FROM Contacts INNER JOIN Customers ON Contacts.UserCode = Customers.UserCode
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim dtCopy As New DataTable |
To write code in C#
C# |
Copy Code
|
---|---|
DataTable dtCopy = new DataTable; |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Me.ContactsTableAdapter.Fill(Me.DsContacts.Contacts) dtCopy = Me.DsContacts.Tables(0).Copy() |
To write code in C#
C# |
Copy Code
|
---|---|
this.ContactsTableAdapter.Fill(this.DsContacts.Contacts); dtCopy = this.DsContacts.Tables(0).Copy(); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1TrueDBGrid1_UnboundColumnFetch(ByVal sender As System.Object, ByVal e As C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs) Handles C1TrueDBGrid1.UnboundColumnFetch If e.Column.Caption = "Name" AndAlso e.Row < dtCopy.Rows.Count Then e.Value = Me.C1TrueDBGrid1(e.Row, "FirstName").ToString + " " + Me.C1TrueDBGrid1(e.Row, "LastName").ToString End If End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1TrueDBGrid1_UnboundColumnFetch(object sender, C1.Win.C1TrueDBGrid.UnboundColumnFetchEventArgs e) { if(e.Column.Caption == "Name" && e.Row < dtCopy.Rows.Count) { e.Value = this.c1TrueDBGrid1[e.Row, "FirstName"].ToString()+ " " + this.c1TrueDBGrid1[e.Row, "LastName"].ToString(); } } |
When the application runs, it should look like the following:
This concludes this tutorial; you've successfully completed defining unbound columns in a bound grid.