This tutorial demonstrates how to link multiple C1List and C1Combo controls using the Change event to trigger related actions. This technique is particularly useful for displaying master-detail relationships.
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Visual Studio adds these two lines of code to load the data. Me.ComposerTableAdapter.Fill(Me.DataSet1.Composer) Me.OpusTableAdapter.Fill(Me.DataSet2.Opus) Me.dbcComp_RowChange(Nothing, e.Empty) |
To write code in C#
C# |
Copy Code
|
---|---|
// Visual Studio adds these two lines of code to load the data. this.ComposerTableAdapter.Fill(this.DataSet1.Composer); this.OpusTableAdapater.Fill(this.DataSet2.Opus); this.dbcComp.RowChange += new EventHandler(this.dbcComp_RowChange); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub dbcComp_RowChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles dbcComp.RowChange Dim dr As DataRow() dr = Me.DataSet2.Opus.Select("Last ='" & Me.dbcComp.Text + "'") Dim tb As New DataSet2.OpusDataTable() tb = New DataSet2.OpusDataTable() Dim item As DataRow For Each item In dr tb.ImportRow(item) Next item Me.dblOpus.DataSource = tb End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void dbcComp_RowChange(object sender, System.EventArgs e) { DataRow[] dr = this.dataSet2.Opus.Select("Last ='" + this.dbcComp.Text + "'"); DataSet2.OpusDataTable tb = new DataSet2.OpusDataTable(); foreach (DataRow item in dr) { tb.ImportRow(item); } this.dblOpus.DataSource = tb; } |
Change the current record position of dbcComp by selecting a different composer. Observe that dblOpus (the detail list) displays a new set of compositions each time the row changes in C1Combo1 (the master list).
Note: When C1Combo has the focus, press F4 to open the drop-down box.
To end the program, press the End button on the toolbar. This concludes the tutorial.