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.
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,
Code:
cbClient.DataSource = ds.Tables[0];
cbClient.DisplayMember = "CLIENTS";
cbClient.ValueMember = "CLIENTS";
cbClient.SelectedIndex = -1;
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.
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,