日期:2014-05-18  浏览次数:20924 次

WinForm如何将光标定位在DataGridView的某个单元格上
我们可以通过键盘上的TAB键或左右键来指定到DataGridView的某个单元格
上下左右的移动,这里我会触发一个事件:DataGridView1_CellLeave事件
当执行出错时再返回上一个单元格,不知道如何实现
用:this.dg_DataGridView1.Rows[e.RowIndex].Cells[3].Selected = true;
这条语句好像不起作用,谢谢高手指点!

------解决方案--------------------
this.dataGridView1.ClearSelection();
 this.dataGridView1.[e.RowIndex].Cells[3].Selected = true; 

------解决方案--------------------
dataGrid.CurrentCell = new DataGridCell(RowIndex, ColumnIndex);
------解决方案--------------------
dataGrid.CurrentCell = new DataGridCell(RowIndex, ColumnIndex);
这个怎么会报错呢 

报错?我用的是2005
错误贴出来
------解决方案--------------------
DataGridViewCell 而非 DataGridCell!

 wumingbing_8027 用的是DataGrid。
------解决方案--------------------
关注
------解决方案--------------------
1\this.dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
this.dataGridView1.CurrentCell = this.dataGridView1[1, 0];
2\this.dataGridView1.CurrentCell = this.dataGridView1[1, 0];
 this.dataGridView1.BeginEdit(true);

dataGridView1[1, 0] = dataGridView1[ColumnIndex, RowIndex],这个和习惯不一样
第二种方法不能放在form_onload里
------解决方案--------------------

------解决方案--------------------
我非常了解楼主遇到的问题,这也是我曾经做WINFORM开发时提出过的问题,我可以很负责任地告诉楼主如果不采用第三方控件或重写控件的话是无法达到楼主想要的效果的!
话又说回来,楼主如果为了达到这个效果要花很多时间的话我认为是不划算的!我当时的做法就是在信息框弹出后让单元格为选中状态!
------解决方案--------------------
this.dataGridView1.CurrentCell = this.dataGridView1[3, 0];
this.dataGridView1.BeginEdit(true);