Tuesday, July 14, 2009

When i set a combobox's SelectedValue it dosnt work/update?? any help? C# visual studio?

i have retrived values from a database and now populating a form with the info i got 2 combo box's that i would like to popluate with the correct values, acording to the data. however, even if the selectedvalue, selectedindex, or selectedtext is changed, when the form is shown/drawn the combo box's still stay at the first entry from the datasource,





public frmMov(string title, string year, int ratingid, int formatid, string rating, string format)


{


InitializeComponent();


txtTitle.Text = title;


txtYear.Text = Convert.ToString(year);


cmbRating.SelectedValue = ratingid;


cmbFormat.SelectedValue = formatid;











}





why wont it change when the form is drawn am i missing somthing simple?

When i set a combobox's SelectedValue it dosnt work/update?? any help? C# visual studio?
Did you try to store your data(which you have retrieve from the DB) into the variables that you have declared ? If yes, then the below code should work.





if you need to populate the combo box, you need to do this:





cmbRating.Items.Add(ratingid);


cmbFormat.Items.Add(formatid);





If No,


then you should create an arraylist to store the values from DB, loop thru it, then populate ur data in.





hope this helps.


No comments:

Post a Comment