【问题标题】:Set focus to a row in datagridview that has been newly inserted or updated?将焦点设置到新插入或更新的datagridview中的一行?
【发布时间】:2013-11-11 07:52:18
【问题描述】:

如何将焦点设置到 datagridview 中新插入或更新的行?所以插入/更新的人不必去找用户插入/更新的数据。

我可以用这个吗=> (DataGridView - Can focus be placed on the blank row with the (*) using code?)

【问题讨论】:

  • 当您更新一行或插入一行时,您应该知道如何在网格中识别该行并手动执行selecting

标签: c# sql winforms datagridview


【解决方案1】:

早上好,

if (theGrid.Rows.Count > 0)
        {
            theGrid.CurrentCell = theGrid.Rows[theGrid.Rows.Count - 1].Cells[0];
        }
        SendKeys.Send("{DOWN}");

转到最后一行并找到新行。

【讨论】:

    【解决方案2】:

    试试看,可能对你有帮助,

         // dataGridView1.Rows[0].Cells[1].Selected = true;
    dataGridView1.Focus();
    dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[2];
    

    如果它以交叉线程废话结束.. 然后调用新方法。

    【讨论】:

    • 我更新了,它的工作原理,如果它也对你有用,请将其标记为答案。
    • 它也不起作用.. Datagridview 的焦点只停留在 datagridview 的第一行。
    • focus() 是将焦点设置为网格,以防网格不在焦点上,它在我这边工作,dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[2];还要检查网格选择模式应该是 rowheaderselect
    • 是的,它正在工作,但我希望它选择新插入的行。
    【解决方案3】:

    只需更改行索引

    dataGridView1.CurrentCell = dataGridView1.Rows[datagridview.rows.count].Cells[2];
    

    【讨论】:

    • 只需更改行索引”是什么意思。
    • debug more to understand the concept in deep,int x=0;//x是你要设置焦点的行索引,int y=0;//y列索引dataGridView1.CurrentCell =dataGridView1.Rows[x].Cells[y];
    【解决方案4】:
    int LastIndex = dataGridView1.Rows.Count - 1;
    dataGridView1.Rows[LastIndex].Cells[1].Focus();
    

    这就是你在asp.net c#中的做法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多