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);
}
}