Combobox Issue

PROKA

Junior Contributor
Joined
Sep 3, 2003
Messages
249
Location
Bucharest
I have a combobox bound to a table ( .Datasource = table ) . The problem is that I MUST use that table to fill another combobox. When I clear the table to retrieve the data for the 2nd cmb, the first one raises an exception.

Any ideeas on how to solve it?


I am trying to fill the combobox without specifying the .Datasource.

but ... how do I set THE VALUE for an item I'm adding to the combo box?
 
idea?

This may be too simple of an answer, but can you load the combobox with the values from the table rather than binding it? IE loop through all the rows and take the value in the column you want and combobox.items.add(value)?

Then when you clear the table to reload it, the combobox wouldn't care; that might break whatever else you're needing to do though, sorry if i'm in right field.

PROKA said:
I have a combobox bound to a table ( .Datasource = table ) . The problem is that I MUST use that table to fill another combobox. When I clear the table to retrieve the data for the 2nd cmb, the first one raises an exception.

Any ideeas on how to solve it?


I am trying to fill the combobox without specifying the .Datasource.

but ... how do I set THE VALUE for an item I'm adding to the combo box?
 
well The table has 2 rows .... .text and .value


an item in a combo box has a text and a value

(.SelectedText , .SelectedValue)

I want to write both of these when adding the item
 
ok, that's not it, i see what you're talking about; you're wanting to set the value to your .value and text to your .text; so I am off in outer space!

PROKA said:
well The table has 2 rows .... .text and .value


an item in a combo box has a text and a value

(.SelectedText , .SelectedValue)

I want to write both of these when adding the item
 
Last edited:
You could combine alreadyused's suggestion with a class and everything should work ok. What I mean by this is you create a loop to loop through all the items and for each item you create an instance of a class that has two properties. You can then assign one property as the DataMember and the other as the ValueMember. Might not be the best way of doing it, but it should work.
 
Similar Question

I am writting a program that connects to an access database, queries employee names, stores these names in an ArrayList, and are added to the comboBox item list. Currently, I have the program querying the database after I change the selectedIndex of the comboBox but the problem is this, dupelicate names are being added to the comboBox which are out of the Array Index (I am using ArrayList.Clear()). The next thing I have tried is having the comboBox items cleared after the Selected Index is changed but this poses a problem, the current selected index is cleared and there is no telling what employee you are looking at. Are there any other solutions to this problem or do I just have to settle with the selected index being cleared? This is in C# and .NET 2.0 btw

Thanks in advance,
Patrick
 
Last edited:
Perhaps I'm missing the point here somewhere, but why are you clearing the list at all? If I'm understanding you correctly then your application queries the database and returns a list of names. These names are then stored in an arraylist aswell as in the combobox. Now it seems to me that your saying when you select an item in the combobox you are re-querying and thus re-populating the arraylist and the combobox. I guess what I'm trying to say is why does selecting a single item from the list require the list to be updated?

I would have thought that when you select a name in the comobox you would want to perhaps populate other controls with information about that person. But I can't see why selecting that person requires the list of people to be updated?
 
OK, when I query the database I add the names to the combobox and the corresponding ssn in the array list. When I change the SelectedIndex, my connectToAccess method is again called using the selected employee's ssn. When a name is selected a list of documents related to their name is displayed in a listbox that can be viewed later. The following pastebin shows my (messy) connectToAccess method and the code that is executed when the employee is changed.

http://pastebin.com/554758

If anyone knows how to do this better I am open to ideas.
 
Back
Top