September 5th, 2005, 01:02 PM
Clearing a Combobox with a DataSource [C#]
Given a Combobox [cbClient] that has been populated by a DataSet [ds] as such:
Problem is I can't seem to find a way to CLEAR/EMPTY the combobox when I want to, meaning if the user presses the "CLEAR" button I want the combobox [cbClient] to become empty.
cbClient.DataSource = ds.Tables;
cbClient.DisplayMember = "CLIENTS";
cbClient.ValueMember = "CLIENTS";
cbClient.SelectedIndex = -1;
I tried stuff like "cbClient.Items.Clear()" but that gave errors like "Cannot modify the items collection when the DataSource property is set", I then tried using stuff like "cbClient.DataSource = null" but that does something really odd to the GUI of the Combobox (looks like the app crashed) and stuff like .Dispose() doesn't seem to work.
Some have hinted that I need to edit the DATASOURCE (dataset ds) itself, I don't want to do it (seeing as I reuse it) I just want to clear the combobox so the user doesn't see anything in it at thay moment, maybe in the future I will rebind it
Any hints/Help/Clues would be much appreciated. Thanks,
Click Here to Expand Forum to Full Width