我想通過這個代碼無法選擇或取消DataGridViewCheckBoxColumn細胞編程
foreach (DataGridViewRow dgvUser in UsersGrid.Rows)
{
dgvUser.Cells["ChkSelect"].Value = true;
}
改變DataGridViewCheckBoxColumn的項目改變checkboxs的價值,但在UI逗留取消選中checkboxs。
怎麼辦?
我想通過這個代碼無法選擇或取消DataGridViewCheckBoxColumn細胞編程
foreach (DataGridViewRow dgvUser in UsersGrid.Rows)
{
dgvUser.Cells["ChkSelect"].Value = true;
}
改變DataGridViewCheckBoxColumn的項目改變checkboxs的價值,但在UI逗留取消選中checkboxs。
怎麼辦?
然後您需要更新Datagridview並刷新。
DataGrid_ABC.Update();以更新gridview中的更改
此處的問題是DataGridViewCheckboxCell
與其他單元格的行爲不同。出於某種原因,這是用來確定複選框應該如何繪製的屬性(選中或取消選中)不Value
但FormattedValue
我的感覺是,雖然該值二傳手已DataGridViewCheckBoxCell被重寫正確行事。所以,如果你把它叫做一個DataGridViewCell
您正在使用的基地一個(不影響FormattedValue的),而如果你投的細胞的事情應該工作:
((DataGridViewCheckBoxCell) dgvUser.Cells["ChkSelect"]).Value = true;
這也沒有幫助。 –
我有這個確切的問題時,我試圖清理等複選框列在同一行中(在CellValueChanged方法中執行)。要解決我的問題,我需要下面的代碼:
private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// filter for valid DataGridViewCheckBoxCell columns, if desired
dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
您是否在GridView上設置了這些屬性? http://stackoverflow.com/a/4126497/1073107 – dash
張貼的代碼作品。問題在別的地方。 – LarsTech