简体   繁体   English

为什么我datagridview.currentcell不会将光标定位在所需的单元格中?

[英]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() . 我已经使用CurrentCellBeginEdit()尝试了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.

相关问题 当对datagridview进行C#过滤时,如何将textbox.Text中的文本添加到datagridview.CurrentCell中? - How can I add text from textbox.Text to datagridview.CurrentCell when datagridview is filtered C#? DataGridView专注于单元格,在使用CurrentCell的情况下,我只剩下一个只能填写1个字符的单元格,为什么? - DataGridView focus on cell, with CurrentCell leave me with a cell where I can only fill in 1 character, why? 为什么DataGridView不显示数据绑定值? - Why wouldn't a DataGridView show the Databound values? 无法为DataGridView设置CurrentRow / CurrentCell - Can't set CurrentRow/CurrentCell for DataGridView 在编辑datagridview单元格时; 用鼠标单击将光标定位在任何位置 - While editing datagridview cell; position cursor anywhere with mouse click DataGridView设置CurrentCell不起作用 - DataGridView set CurrentCell not working 在DataGridView上设置下一个CurrentCell - Set next CurrentCell on DataGridView 为什么用Cursor.Position不能将鼠标光标移动到我告诉它的位置? - Why won't my mouse cursor move where I tell it to go with Cursor.Position? 如何在DataGridView中获取CurrentCell位置 - How to get CurrentCell location in DataGridView 分配currentcell datagridview时发生异常 - exception when assigning currentcell datagridview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM