[英]why i datagridview.currentcell wouldn't position the cursor in the desired cell?
For the testing purposes, i have added a simple datagridview datagridview2
control with two columns on to a form. 为了进行测试,我在表单上添加了一个简单的datagridview
datagridview2
控件,其中有两列。 then i have used to Load()
event of the form to add an empty row to the datagridview and written the following code to place the cursor in the first cell. 然后我已经习惯了窗体的
Load()
事件向datagridview添加一个空行,并编写了以下代码以将光标置于第一个单元格中。
private void Form1_Load(object sender, EventArgs e)
{
dataGridView2.Rows.Add();
//dataGridView2.BeginEdit(true);
//dataGridView2[1, 0].Selected = true;
// dataGridView2.Select();
dataGridView2.CurrentCell = dataGridView2[0,0]; //.Row(1).Cells(0)
//dataGridView2.Focus();
dataGridView2.BeginEdit(false);
}
i have tried the Focus(
), Selected
property and Select()
with CurrentCell
and BeginEdit()
. 我已经使用
CurrentCell
和BeginEdit()
尝试了Focus(
), Selected
属性和Select()
BeginEdit()
。 But this does not place the cursor in the first cell . 但这不会将光标置于第一个单元格中 。
Here is the video capture of the form 这是表格的视频截图
PS- I have an original installation of VS 2010 ultimate (WITHOUT any service packs). PS-我有VS 2010 Ultimate的原始安装(没有任何Service Pack)。 I was wondering this could be the problem.
我想知道这可能是问题所在。 But Could anyone point me where the problem is?
但是有人可以指出问题所在吗?
Um, the form hasn't even been displayed when the Load event handler is executed so how can you start editing a cell? 嗯,执行Load事件处理程序时甚至没有显示该表单,那么如何开始编辑单元格呢? Try doing that in the Shown event handler, which is executed after the form is displayed, and you should see what you expect.
尝试在Shown事件处理程序中执行此操作,该事件处理程序在显示表单后执行,您应该看到期望的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.