WinCE开发中的DataGrid控件没有选中行的属性,但是我们可以通过另外一种方式来模拟选中一行的效果,要实现这个效果需要为控件添加GotFocus和CurrentCellChanged事件。实现的代码如下:
private void dataGrid1_GotFocus(object sender, EventArgs e)
{
DataGrid dataGrid1 = sender as DataGrid;
int index = ((DataGrid)sender).CurrentCell.RowNumber;
if (((DataTable)(dataGrid1.DataSource)).Rows.Count > 0)
{
((DataGrid)sender).Select(index);
}
}
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
DataGrid dataGrid1 = sender as DataGrid;
int index = ((DataGrid)sender).CurrentCell.RowNumber;
if (((DataTable)(dataGrid1.DataSource)).Rows.Count > 0)
{
((DataGrid)sender).Select(index);
}
}
本文介绍在WinCE开发中,如何通过添加GotFocus和CurrentCellChanged事件,使用DataGrid控件模拟选中行的效果。代码示例展示了如何在事件触发时选择当前单元格所在的行。
5164

被折叠的 条评论
为什么被折叠?



