reagan123 Posted January 3, 2006 Posted January 3, 2006 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. 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. Quote
rfazendeiro Posted January 4, 2006 Posted January 4, 2006 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. Quote
reagan123 Posted January 4, 2006 Author Posted January 4, 2006 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!! Quote
Cags Posted January 4, 2006 Posted January 4, 2006 You mean like this.. bob.SelectedIndex = bob.Items.IndexOf("subscriptionID") Quote Anybody looking for a graduate programmer (Midlands, England)?
reagan123 Posted January 4, 2006 Author Posted January 4, 2006 i think that may do the trick... i'll give it a shot later, thanks for the suggestion. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.