loading a combobox without repitition, how to??
-
Hi, I want to check if an item read from a database exists in the combobox before I add it to the combobox, so that the item is not repeated in the combox. For example I want to check for the reader["Area"] doesn't exist in "comboArea", if it doesn't exist, then add it to the combobox. how can I translate that in C# language?? I'm not sure how it's written. If anybody has anybody has any idea how to do this, plz send it.
-
Hi, I want to check if an item read from a database exists in the combobox before I add it to the combobox, so that the item is not repeated in the combox. For example I want to check for the reader["Area"] doesn't exist in "comboArea", if it doesn't exist, then add it to the combobox. how can I translate that in C# language?? I'm not sure how it's written. If anybody has anybody has any idea how to do this, plz send it.
-
thnx for the fast reply, I used this function: myComboBox.Items.Contains() but the problem is that it takes ListItem, and in my case I want to check reader["Area"] retrieved from a database, so it refuses this as an argument to the function..so is there any other way??
-
thnx for the fast reply, I used this function: myComboBox.Items.Contains() but the problem is that it takes ListItem, and in my case I want to check reader["Area"] retrieved from a database, so it refuses this as an argument to the function..so is there any other way??
-
thnx for the fast reply, I used this function: myComboBox.Items.Contains() but the problem is that it takes ListItem, and in my case I want to check reader["Area"] retrieved from a database, so it refuses this as an argument to the function..so is there any other way??
Nada Adel wrote:
I used this function: myComboBox.Items.Contains() but the problem is that it takes ListItem,
Huh? Does this work? (Obviously I'm writing this out of context since I'm not familiar with your application, but hopefully you get what I mean).
myComboBox.Items.Clear();
foreach (Object o in objectsRetrievedFromDatabase) {
if (!myComboBox.Items.Contains (o)) {
myComboBox.Items.Add (o);
}
}/ravi
This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com
-
Nada Adel wrote:
I used this function: myComboBox.Items.Contains() but the problem is that it takes ListItem,
Huh? Does this work? (Obviously I'm writing this out of context since I'm not familiar with your application, but hopefully you get what I mean).
myComboBox.Items.Clear();
foreach (Object o in objectsRetrievedFromDatabase) {
if (!myComboBox.Items.Contains (o)) {
myComboBox.Items.Add (o);
}
}/ravi
This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com
-
Hi, I want to check if an item read from a database exists in the combobox before I add it to the combobox, so that the item is not repeated in the combox. For example I want to check for the reader["Area"] doesn't exist in "comboArea", if it doesn't exist, then add it to the combobox. how can I translate that in C# language?? I'm not sure how it's written. If anybody has anybody has any idea how to do this, plz send it.
As an alternative to what people have said, is there any sort of pre-population of the items in the combobox? If you're just populating the CB from items in a database, and you don't want things to repeat, just use DISTINCT in the query from the database (I'm assuming SQL here), and just use the combobox.displaymember, combobox.valuemember, and combobox.datasource to set it up.