-
September 5th, 2005, 01:02 PM
#1
Clearing a Combobox with a DataSource [C#]
Given a Combobox [cbClient] that has been populated by a DataSet [ds] as such:
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,
-
September 6th, 2005, 03:05 AM
#2
Re: Clearing a Combobox with a DataSource [C#]
Code:
comboBox1.DataSource = null;
This worked for me.
-
September 6th, 2005, 09:58 PM
#3
Re: Clearing a Combobox with a DataSource [C#]
And it didn't do anything odd to your Combobox?
Mine is "frozen", the picture on my form isn't even there properly..
....odd....
-
September 6th, 2013, 02:15 AM
#4
Re: Clearing a Combobox with a DataSource [C#]
comboBox1.DataSource = null; will solve ur problem..if you not yet find solution , plz find the following c# combobox fill from datasource.
Manly
-
September 6th, 2013, 04:47 AM
#5
Re: Clearing a Combobox with a DataSource [C#]
Thanks for your eagerness to help manlypullock. Remember though, that this thread is 8 years old and the problem has long since been resolved. Please do not revive old threads - there are plenty of current threads that need help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|