I want to read the the combobox column as shown in the picture, i've tried using string mode = dt.Rows[0]["Mode"].ToString(); But it doesn't work, it read the USID column instead. How to read the combobox value?
private void getmode()
{
//from here
var modelist = new List<string>() { "Reg0", "Basic", "Extended" };
dgvmode.DataSource = modelist;
dgvmode.HeaderText = "Mode";
dtDataGridView.Columns.Add(dgvmode);
// until here, i've create a combobox column in my datatable
string mode = dt.Rows[i]["Mode"].ToString(); // this line got error, it can't read the "Mode" column and say it is not exist, but in my picture, it is exist as a combobox column.
Messagebox.Show(mode); // here to show i get the combobox value
}
CodePudding user response:
datatable is unable to reada datagridview feature, thus, when i using
yourdatatable.Rows[i]["Mode"].ToString();
it will comes out an error (something likie "Mode" column doesnt exist)
even you change the "Mode" to an integer that indicate the column you want to read, it will automatically read the column that create by datatable only. For example : yourdatatable.Rows[i][0].ToString(); it wont read the combobox column and it will read normal column instead (will not read combobox column ("Mode"), which is the first column. But it will read the column ("USID"), which is the second column).
then, i need to use datagridview like the code below to read the combobox value: yourDataGridView.Rows[i].Cells[0].Value.ToString()