我正在致力於DataGridView
,名爲ListingGrid
,嘗試激活/停用已在DataGridViewCheckBoxColumn
內的任何DataGridViewCheckBoxCell
上「檢查過」的用戶。從DataGridViewCheckBoxCell獲取價值
這是即時通訊的方式試圖做的是:
foreach (DataGridViewRow roow in ListingGrid.Rows)
{
if ((bool)roow.Cells[0].Value == true)
{
if (ListingGrid[3, roow.Index].Value.ToString() == "True")
{
aStudent = new Student();
aStudent.UserName = ListingGrid.Rows[roow.Index].Cells[2].Value.ToString();
aStudent.State = true;
studentList.Add(aStudent);
}
}
}
據我得到的,當你檢查DataGridViewCheckBoxCell
,該單元格的值是true
吧?但它不允許我將該值轉換爲布爾值,然後進行比較,並向我拋出一個無效的轉換異常。
HTTP的可能重複: //stackoverflow.com/questions/1563190/how-to-verify-if-a-datagridviewcheckboxcell-is-checked –
也許並不完全與此問題有關,但這可能有所幫助:https://stackoverflow.com/a/48465766/5750078 – Loaderon