combobox - C#: Using one Data Table in order to fill 2 different comboboxes? -


I have 2 combobox, which is called form 1 as combobox 1 and compbx 2.

Each combobox should be in SQL Server 2005 filled with 2 data stored in different tables: Table 1 and Table 2

I mean: combobox1 -> table1 combobox2 -> table2

I fill out the data table with the appropriate data

My problem is: After filling 2 combo, the data equal to the two of them is found in Table 2.

This is my code:

  datatelle tb1 = new datatyla (); // Filling the TB1 with data is found from table1 combobox1. Items.Clear (); Combobox1.DataSource = tb1; Combobox1.DisplayMember = "name"; Combobox1.ValueMember = "ID"; Combobox 1 Selected index = -1; // Filling TB1 with data, found in Table 2 combobox 2 ITEMS. Clear (); Combobox 2 Data source = TB1; Combobox2.DisplayMember = "name"; Combobox 2 Value = "id"; Combobox 2 Selected index = -1;  

What's wrong?

It seems that if I get 2 different data tables (TB1 and TB2), then everything will be fine.

Any suggestions please

Thanks

datatyla is a reference type, Which means that when you specify TB1, a control datasource, you are actually assigning a reference / link in memory to DataSource . For this, when you modify the TB1 variable, you are referencing reference references yourself. Because you are only changing the reference, DataSource still appears on the same DataTable , only now it has a separate set of data.


Comments