vb.net 数据网格视图单元格聚焦

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7900359/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:45:44  来源:igfitidea点击:

Data Grid View Cell Focused

vb.net

提问by Furqan Sehgal

I have a datagrid view that loads data from a database. This is unbound datagridview. The columns are Description, UPrice, Quantity and Total

我有一个从数据库加载数据的数据网格视图。这是未绑定的数据网格视图。列是描述、UPrice、数量和总计

Description UPrice come from database then quantity is typed. I want it so that when my datagrid loads, cursor goes to Quantity column and it is shown blinking like we have in text boxes.

描述 UPrice 来自数据库,然后输入数量。我想要这样,当我的数据网格加载时,光标会转到 Quantity 列,并且它会像我们在文本框中一样闪烁。

Please advise how to do it. Thanks

请指教怎么做。谢谢

回答by Enigma State

you can do like this...

你可以这样做...

Set the Current Cell like:

设置当前单元格,如:

DataGridView1.CurrentCell = DataGridView1.Item(1, 5)

or

或者

DataGridView1.CurrentCell = DataGridView1.Item("ColumnName", 5)

and you can directly focus with Editing by:

您可以通过以下方式直接专注于编辑:

dataGridView1.BeginEdit(true)

or you can try like this...

或者你可以像这样尝试......

problem with datagridview is that it select the first row automatically so you want to clear the selection by

datagridview 的问题是它自动选择第一行,所以你想清除选择

grvPackingList.ClearSelection();
dataGridView1.Rows[rowindex].Cells[columnindex].Selected = true;  

回答by zmaggie

You have to combine these lines to set focus on a cell:

您必须组合这些行以将焦点设置在单元格上:

dataGridView1.ClearSelection()

DataGridView1.CurrentCell = DataGridView1.Item("ColumnName", 5)

dataGridView1.BeginEdit(true)