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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-12-27
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-05-20
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案