vb.net 在数据网格视图 .NET 中设置单元格焦点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25822853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
set cell focus in data grid view .NET
提问by A Koul
In my datagridview (Mydgv1),I want to set fourth cell into focus and edit it, after i leave the first cell. On first cell's leave event , i have written the code to focus the 4th cell, it comes into focus, but there is no cursor in it, and then the focus shifts to second cell and second cell becomes blue(by default highlighted cell in datagridviews). Please post some code for it. So far I have tried this.
在我的 datagridview (Mydgv1) 中,我想在离开第一个单元格后将第四个单元格设置为焦点并对其进行编辑。在第一个单元格的离开事件中,我编写了代码来聚焦第 4 个单元格,它进入焦点,但没有光标,然后焦点转移到第二个单元格,第二个单元格变为蓝色(默认情况下,datagridviews 中突出显示的单元格)。请发布一些代码。到目前为止,我已经尝试过这个。
Mydgv1.ClearSelection()
Mydgv1.CurrentRow.Cells(3).Selected = True
Mydgv1.BeginEdit(False)
回答by Bedford
BeginEdit will only have effect on the current cell (marked by the CurrentCell property of the DataGridView object). Selecting it won't help (especially since you can select multiple cells in some DataGridView configurations). Instead try this:
BeginEdit 将只对当前单元格有效(由 DataGridView 对象的 CurrentCell 属性标记)。选择它无济于事(特别是因为您可以在某些 DataGridView 配置中选择多个单元格)。而是试试这个:
Dim ColumnIndex As Integer = 3
Mydgv1.CurrentCell = Mydgv1.CurrentRow.Cells(ColumnIndex)
Mydgv1.BeginEdit(False)

