1
我有一個datagridview與列索引12中的複選框。toolsstrip上有一個按鈕需要迭代這些選中的行並刪除項目。DataGrid視圖複選框沒有被選中作爲檢查
我有的代碼是沒有檢測到單元格被檢查(bChecked變量總是爲false),它的值在調試時爲false。
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCheckBoxCell oCell = row.Cells[12] as DataGridViewCheckBoxCell;
bool bChecked = (null != oCell && null != oCell.Value && true == (bool)oCell.Value);
if (bChecked == true)
{
//Do something
}
}
任何想法?
謝謝。
是否有可能您的索引(12)錯了,並且您正在閱讀其他一些專欄。如果'DataGridView'的列預定義了,那麼最好使用像row.Cells [this.dgvCheckBoxColumn.Name]這樣的列變量'對不起,當看到一個硬編碼的值時,我總是填寫不好的:) – Fabio