I just started learning C# yesterday. I am working with windows form. I could retrieve data from database and display them in combo box list. But for data update, the combo.SelectedValue
does not work. I have tried combo.selectedItem
, but still, it does not work. What should i do?
selectedDescription = dr["value"].ToString().Split(',').ToList<string>();
if (dr["type"].ToString() == "multiple") {
ComboBox combo = new ComboBox();
combo.DataSource = selectedDescription;
combo.Width = 60;
combo.Height = 27;
combo.Location = new Point(currentX, currentY);
combo.Tag = Id;
Code to retrieve data is as follows:
if (getVal != null) {
foreach (DataRow ds in getVal.Tables[0].Rows) {
if (Convert.ToInt32(ds["descId"].ToString()) == combo.Tag) {
combo.SelectedValue = ds["val"].ToString();
}
I've tried something like this, but it doesn't work either:
List<string> str = (List<string>)combo.DataSource;
str.Add(ds["val"].ToString());
combo.DataSource = null;
combo.DataSource = str;
combo.Text = ds["val"].ToString();