日期:2014-05-19  浏览次数:20842 次

如何让某个单元格进入编辑状态
环境:
.net框架2.0

问题描述:
在DataGridView中当前我正在编辑某个单元格,这时我想用代码的方式让另外一个单元格进入编辑状态,我用如下的代码,但是会抛出异常:

this.DataGridView1.CurrentCell   =   this.DataGridView1.Rows[3].Cells[2];
this.DataGridView1.EditMode   =   DataGridViewEditMode.EditOnEnter;
this.DataGridView1.BeginEdit(True);

------解决方案--------------------
你可能选的事件不合适,但是用
this.DataGridView1.CurrentCell = this.DataGridView1.Rows[3].Cells[2];
this.DataGridView1.BeginEdit(True);
是可以编辑指定的单元格的,没有问题.
------解决方案--------------------
应该可以.
检查上下文.
------解决方案--------------------
没看出什么问题,请问抛出的是什么异常?
------解决方案--------------------
hbxtlhx(平民百姓) ( ) 信誉:112 Blog 2007-03-24 15:36:21 得分: 0


你可能选的事件不合适,但是用
this.DataGridView1.CurrentCell = this.DataGridView1.Rows[3].Cells[2];
this.DataGridView1.BeginEdit(True);
是可以编辑指定的单元格的,没有问题.
---------------------------------------
正解

------解决方案--------------------
你在哪个事件中做的
好DataGridView1中的cell的双击事件中写吧
你是否固定只编辑CurrentCell

this.DataGridView1.CurrentCell = this.DataGridView1.Rows[3].Cells[2];
this.DataGridView1.BeginEdit(True);
是可以编辑指定的单元格的,没有问题.