ComboBox
-
Hi , I have a dataTable and this table is binded into 10 comboBoxes , but whenever I select an item in a combobox, all the comboBoxes change their value too. I guess its because of habing same source, is there any method to force to let the user select whatever he/she wants rather than changing tableName and binding each ComboBox unique ? Thanks Bahadir Cambel
-
Hi , I have a dataTable and this table is binded into 10 comboBoxes , but whenever I select an item in a combobox, all the comboBoxes change their value too. I guess its because of habing same source, is there any method to force to let the user select whatever he/she wants rather than changing tableName and binding each ComboBox unique ? Thanks Bahadir Cambel
Thats a great question!. The dafault behaviour is windows forms creates at least one currency manager object for each data sources included in the form. The currency manager is managed through BindingContext object. This behaviour is intentionally incorporated in order to keep all the controls on the form synchronized with data source. For Instance if you have two combo boxes FirstName and LastName bound to dsCustomer, then if user changes FirstName, the lastname column also changes in order to reflect the correct customer. Windows forms moves binding context beind the scenes and programmer is relived of writing code to synchronize the controls. If you do not want this feature, then you need to make a copy of the datasource and then bind it to combo boxes as illustrated in the code below. private void Form1_Load(object sender, System.EventArgs e) { System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("Select top 10 * from authors", "Data Source=ITD2142s;Initial Catalog=pubs;Integrated Security=SSPI;"); ds = new System.Data.DataSet(); da.Fill(ds); comboBox1.DataSource = ds.Copy().Tables[0] ; comboBox1.DisplayMember = "au_lname"; comboBox2.DataSource = ds.Copy().Tables[0] ;; comboBox2.DisplayMember = "au_fname"; } Hope this helps ;). Cheers Ravindra Sadaphule MCSD.NET
-
Thats a great question!. The dafault behaviour is windows forms creates at least one currency manager object for each data sources included in the form. The currency manager is managed through BindingContext object. This behaviour is intentionally incorporated in order to keep all the controls on the form synchronized with data source. For Instance if you have two combo boxes FirstName and LastName bound to dsCustomer, then if user changes FirstName, the lastname column also changes in order to reflect the correct customer. Windows forms moves binding context beind the scenes and programmer is relived of writing code to synchronize the controls. If you do not want this feature, then you need to make a copy of the datasource and then bind it to combo boxes as illustrated in the code below. private void Form1_Load(object sender, System.EventArgs e) { System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("Select top 10 * from authors", "Data Source=ITD2142s;Initial Catalog=pubs;Integrated Security=SSPI;"); ds = new System.Data.DataSet(); da.Fill(ds); comboBox1.DataSource = ds.Copy().Tables[0] ; comboBox1.DisplayMember = "au_lname"; comboBox2.DataSource = ds.Copy().Tables[0] ;; comboBox2.DisplayMember = "au_fname"; } Hope this helps ;). Cheers Ravindra Sadaphule MCSD.NET
Thanks a lor Ravinda , I used .Clone() function but it didnt work.. Well at least I should have given one more try :D I have a one more question , Is this copied dataTable will be stored logically or physically in memory ? Thanks in advance.. Bahadir Cambel
-
Thanks a lor Ravinda , I used .Clone() function but it didnt work.. Well at least I should have given one more try :D I have a one more question , Is this copied dataTable will be stored logically or physically in memory ? Thanks in advance.. Bahadir Cambel
Clone function will only copy the structure not the data. Copy function will copy both structire as well as data. Hence Copy function is more relevant in this case. The copied data will be stored physically in memory. Ravindra Sadaphule MCSD.NET
-
Clone function will only copy the structure not the data. Copy function will copy both structire as well as data. Hence Copy function is more relevant in this case. The copied data will be stored physically in memory. Ravindra Sadaphule MCSD.NET
Thanks again for great help... Bahadir Cambel