2句搞定 DataGridView 让选中行在可视范围内

listview中有一个属性 EnsureVisible  可以保证选中行在可视范围内.如下描述:

ListView problem
--------------------------------------------------------------------------------

Hello,

Anyone know how to scroll down the listview by code?
Eg. I have 200 items in the listview. When I set the selectedItem to be
item 180, the user cannot see it if he don''t scroll it down.

Thanks!
 
Re: ListView problem
--------------------------------------------------------------------------------

Use the EnsureVisible method. Pass in the index of the item you want to
scroll into view.
____________________
Klaus H. Probst, MVP


那么C#中的DataGridView呢?
虽让DataGridView没有那么直接的方法但是还是可以变通实现的,如下:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
arow.Selected = true;//选中某行
DataGridView.FirstDisplayedScrollingRowIndex = arow.Index; //让选中行显示在可视范围内
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

FirstDisplayedScrollingRowIndex 这个属性的意思蛮不好理解的.

 

文章出处:飞诺网(www.firnow.com):http://dev.firnow.com/course/4_webprogram/asp.net/asp_netshl/2008131/98223.html

posted on 2010-11-26 12:13  peter_zhang  阅读(783)  评论(0编辑  收藏  举报