setting combo box from database value...?

reagan123

Freshman
Joined
Feb 16, 2005
Messages
38
ok, should be simple, but i'm having a hard time getting this to work. I have a combo box that is populated with the following.

Code:
da.Fill(ds, "Subscription");
cboSubscriptions.DataSource = ds.Tables["Subscription"];
cboSubscriptions.DisplayMember = "SubscriptionNo";
cboSubscriptions.ValueMember = "SubscriptionID";

Value Member         DisplayMember
1                            2323235235
2                            3352525233
3                            4564564564
etc....

This works fine but once the combo box is populated is where i'm having my trouble. I'm getting some values out of a database table that have the 'SubscriptionID' in it. How can I take the database value and then have the combo box selected based off of that value.

If i'm pulling a subscriptionID of '2' out of the database, i need to set the combo box to show 3352525233.

thanks.
 
Try doing it this way

da.Fill(ds, "Subscription");
cboSubscriptions.DisplayMember = "SubscriptionNo";
cboSubscriptions.ValueMember = "SubscriptionID";
cboSubscriptions.DataSource = ds.Tables["Subscription"];

I dont no exactly why but i already got that problem and solved it by defining first the display member and the value member.
 
hmm. not quite my problem. let me try and re-explain. I am populating a combo box from a table called subscriptions. This table has 'subscriptionID' and 'subscription' in the table. I'm putting the 'subscriptionID' field in the combo box value member and putting the 'subscription into the display member.

Once that is loaded, i'm pulling a record out of a table that contains 'softwareID', 'softwareName', 'binderID', 'subscriptionID'. I need to make the dropdown box be selected to the value of subscriptionID from this table. Basically, if the record I pull out of the second table has a 'subscriptionID' of 2, then the dropdown box needs to be on the item that has the valuemember of 2.

Does that make sense?

thanks so far for the help!!
 
Back
Top