如何从datagrid获取datagridcell
问题描述:
我如何从datagrid获取Datagridcell对象。
我正在选择Cell但我也想要未选择的单元格。我怎么能做到这一点。请提出建议。
How i can get the Datagridcell object from datagrid.
I am getting selected Cell but i also to want unselected cell. How i can achieve this. Please suggest something.
答
不确定您想说什么,但如果您的意思是我如何取消选择所选单元格...
单个单元格:
Not sure what your trying to say, but if you mean how do I unselect a selected cell...
for a single cell:
// Cell, DataGridView[columnindex, rowindex]
MyGrid[0, 0].Selected = false;
所有选定单元格的
:
for all selected cells:
if(MyGrid.SelectedCells.Count != 0)
for(int i = 0; i < MyGrid.SelectedCells.Count; i++){
MyGrid.SelectedCells[i].Selected = false;
}
您可能需要在DataGridView上调用invaliate以反映更改。
you may need to call invaliate on the DataGridView to reflect the changes.
//Invalidate, DataGridView to redraw its surface.
MyGrid.Invalidate();