【问题标题】:Setting Focus on DataGridView Control programmatically in Visual Basic在 Visual Basic 中以编程方式将焦点设置在 DataGridView 控件上
【发布时间】:2009-08-10 22:40:31
【问题描述】:

我想以编程方式将焦点设置到 Visual Basic 的 DataGridView 控件中的最后一行(最底部,只有一列宽)。我该怎么做?

到目前为止,我已经尝试过

DGV.Rows.GetLastRow(DataGridViewElementStates.Selected)

没有成功,虽然我没想到会成功。

它绝对必须选择最后一个单元格。否则,应用程序几乎无法使用!

这是我正在制作的截图:http://www.mediafire.com/?mmyogzytgzt

“粘贴剪贴板内容”按钮仅粘贴到选定的单元格中,但我想我可以找到解决方法。

【问题讨论】:

    标签: vb.net datagridview


    【解决方案1】:

    我解决了。我使用了一种解决方法来直接添加文本。我不再需要这个了!

    【讨论】:

      【解决方案2】:

      要选择 c# 中的最后一列,最后一行(对不起,我现在没有正在工作的 vb 项目:

      this._dg.ClearSelection(); // eliminates what they already have selected if you need
      this._dg[this._dg.ColumnCount-1, this._dg.RowCount-1].Selected = true;
      

      在 VB.net 中,将“this”替换为“me”,将 [] 替换为 ()。

      这也很有用:

      this._dg.Focus();
      this._dg.CurrentCell = this._dg[this._dg.ColumnCount - 1, this._dg.RowCount - 1];
      this._dg.BeginEdit(false); // true if you want all text highlighted 
        // for deletion or replacement
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-04
        • 2020-02-15
        • 1970-01-01
        • 2014-11-22
        • 2021-10-30
        • 2018-10-01
        • 2011-06-23
        • 2021-01-19
        相关资源
        最近更新 更多