This is function that I used to load combobox. I can load combobox but when I try to get
selectedvalue of combobox it showing null; I am not getting the actual value.public static DataTable GetComboBoxedDataTable(DataTable oldDataTable, string valueColumn, string textColumn, string topRowValue, string topRowText, ComboBox cmb) { DataTable newDataTable = new DataTable(); newDataTable.Columns.Add(valueColumn); newDataTable.Columns.Add(textColumn); foreach (DataRow oldDR in oldDataTable.Rows) { DataRow newDR = newDataTable.NewRow(); newDR[0] = oldDR[valueColumn].ToString(); newDR[1] = oldDR[textColumn].ToString(); newDataTable.Rows.InsertAt(newDR, newDataTable.Rows.Count); } // Add your 'Select an item' option at the top DataRow dr = newDataTable.NewRow(); dr[0] = topRowValue; dr[1] = topRowText; newDataTable.Rows.InsertAt(dr, 0); cmb.ValueMember = valueColumn; cmb.DisplayMember = textColumn; return newDataTable; }the code where i am in need of combobox.selectedvalueprivate void cmbroomno_SelectedIndexChanged(object sender, EventArgs e) { try { object[,] ParamArray = new object[,] { { "@RoomID", cmbroomno.SelectedValue } };---code where i need selected value DataSet ds = new DataSet(); ds = DB.ExecuteQuery_SP("SelectGuestDetailsForService", ParamArray); 
Arunava BhattacharjeePosted Aug 29, 2014, 6:26 AM
SelectedValue is particularly useful when only part of your item is stored in the model you are data binding to.I always use SelectedItem in this conditions as it is bound to original model object. By that you can get your desired property directly. Change your code to SelectedItem then cast it to your original model class.