如何专注于特定的DataGridViewcell()? [英] How to focus to particular DataGridViewcell()?

查看:61
本文介绍了如何专注于特定的DataGridViewcell()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户进入Column_1或Column_2时,我希望将注意力集中在同一行中的一个单元格中。 column_3。

所以我试过以下方式,它没有成功...



感谢帮助&正确的方向...



  private   void  myDataGrid1_CellEnter( object  sender,DataGridViewCellEventArgs e)
{
if (e.RowIndex == 0 &&(e.ColumnIndex == 1 || e.ColumnIndex == 2 ))
{
myDataGrid1.ClearSelection();
DataGridViewCell MyCell = myDataGrid1.Rows [myDataGrid1.CurrentCell.RowIndex] .Cells [ 3 ];
myDataGrid1.CurrentCell = MyCell;
myDataGrid1.Rows [myDataGrid1.CurrentCell.RowIndex] .Cells [ 3 ]。Selected = true ;
}
}

解决方案

我怀疑你忘了设置合适的 SelectionMode

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionmode%28v=vs.110%29.aspx [<一个href =http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionmode%28v=vs.110%29.aspxtarget =_ blanktitle =New Window > ^ ],

http://msdn.microsoft.com/en-us/library/3c89df86%28v=vs.110%29.aspx [ ^ ]。



您需要使用 System.Windows.Forms.DataGridViewSelectionMode.CellSelect



-SA

Hi, While the users enters into Column_1 or Column_2, I wish to focus to a cell in same row & column_3.
So I tried by the following ways, it's not succeeded...

Thanks for the helps & right directions...

private void myDataGrid1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex == 0 && (e.ColumnIndex == 1 || e.ColumnIndex==2 ))
    {
       myDataGrid1.ClearSelection();
       DataGridViewCell MyCell = myDataGrid1.Rows[myDataGrid1.CurrentCell.RowIndex].Cells[3];
       myDataGrid1.CurrentCell = MyCell;
       myDataGrid1.Rows[myDataGrid1.CurrentCell.RowIndex].Cells[3].Selected = true;
    }
}

解决方案

I would suspect that you forgot to set appropriate SelectionMode:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionmode%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/3c89df86%28v=vs.110%29.aspx[^].

You would need to use System.Windows.Forms.DataGridViewSelectionMode.CellSelect.

—SA


这篇关于如何专注于特定的DataGridViewcell()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆