我想讀取如圖所示的組合框列,我嘗試使用 string mode = dt.Rows[0]["Mode"].ToString(); 但它不起作用,它改為讀取 USID 列。如何讀取組合框的值?
資料表
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
}
uj5u.com熱心網友回復:
datatable 無法讀取 datagridview 功能,因此,當我使用
yourdatatable.Rows[i]["Mode"].ToString();
它會出現一個錯誤(類似“模式”列不存在)
即使您將“模式”更改為指示要讀取的列的整數,它也會自動讀取僅由資料表創建的列。例如:yourdatatable.Rows[i][0].ToString(); 它不會讀取組合框列,而是讀取普通列(不會讀取組合框列(“Mode”),這是第一列。但它會讀取列(“USID”),這是第二列)。
然后,我需要像下面的代碼一樣使用 datagridview 來讀取組合框值: yourDataGridView.Rows[i].Cells[0].Value.ToString()
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/506807.html
