如何将焦点设置的特定行一个DataGrid / GridView的? [英] How to set focus on a particular row in a datagrid/gridview?

查看:324
本文介绍了如何将焦点设置的特定行一个DataGrid / GridView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGrid / GridView控件。我填充10行开始并网发电。点击一个按钮,每次,我保持上添加10行到DataGrid / GridView控件。现在,我希望每个填充网格时将焦点设置到最后一行。我可以得到该行的索引,但我不能将焦点设置到特定行。

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;

这篇关于如何将焦点设置的特定行一个DataGrid / GridView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆