如何将焦点设置在数据网格/网格视图中的特定行上? [英] How to set focus on a particular row in a datagrid/gridview?
本文介绍了如何将焦点设置在数据网格/网格视图中的特定行上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据网格/网格视图.我最初用 10 行填充网格.每次单击按钮时,我都会继续向数据网格/网格视图添加 10 行.现在我想在每次填充网格时将焦点设置到最后一行.我可以获得该行的索引,但我无法将焦点设置到该特定行.
I have a datagrid/gridview. I'm populating the grid with 10 rows initially. On a button click every time,I'm keeping on adding 10 rows to the datagrid/gridview. Now I want to set the focus to the last row every time the grid is populated. I can get the index of that row,but I can't set focus to that particular row.
你们有没有人知道如何在 C# 中做到这一点?
Do anyone of you have any idea how to do it in C#?
推荐答案
试试这个
dataGridView1.ClearSelection();
int nRowIndex = dataGridView1.Rows.Count - 1;
dataGridView1.Rows[nRowIndex].Selected = true;
dataGridView1.Rows[nRowIndex].Cells[0].Selected = true;
这篇关于如何将焦点设置在数据网格/网格视图中的特定行上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文