日期:2014-05-18  浏览次数:21742 次

100分求助,WinForm ListView 或DataGridView如何实现自动滚动
先强调一下,是WinForm控件,不是asp.net控件

设置ListView或DataGridView的MultipleSelection属性为false,不让它同时选中多行
比如控件中显示有1000行,通过程序中控制它被选中的行,这一点没有问题。
但是我希望,在程序中如果修改了它们的选中行,控件能够自动滚动,使选中行能够显示出来

例如,在ListView中,View = Detail,显示列表,MultipleSelect = false,一次最多只能选中一行
控件中有1000个item,控件大小一屏只能显示20个item,其它的需要手动滚动条才能显示
如果我设置 ListView 的第900个Item为被选中的Item:
lvData.Items[900].Selected = true;

那么,我希望ListView的滚动条能够自动滚动,使第900个项显示出来

------解决方案--------------------
ListViewItem.EnsureVisible方法应该可以达到你的要求,参考MSDN。
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.listviewitem.ensurevisible.aspx
------解决方案--------------------
lvData.EnsureVisible(899)
or
lvData.EnsureVisible(lvData.Index)
------解决方案--------------------
ListView: EnsureVisible
DataGridView:dataGridView1.FirstDisplayedScrollingRowIndex
------解决方案--------------------
C# code
DataGridView这样就可以了显示某一行了,,滚动条自动滚动  

dataGridView1.CurrentCell = dataGridView1.Rows[899].Cells[0];//选中第900行

------解决方案--------------------
实现自动滚动,你只要把它的当前index设置为最大的一个就可以了

比如以list为例子,List.CurrentIndex=List.Items.Count()-1;
代码随手打的,可能不太对,但是思路是这个。我做TCP通信的时候就这样写的
------解决方案--------------------
不懂.帮顶~
------解决方案--------------------
楼主可以换用datalist实现滚动,主要是<marquee></marquee>来实现的,下面是datalist滚动代码:

下面的滚动鼠浮上去停止滚动,鼠标离开又开始滚动,滚动速度楼主可以根据自己喜好来调!
<marquee direction="up" onmousemove="this.stop()" onmouseout="this.start()" scrollAmount="1" scoreDelay="4" style="width: 90%; height: 180px;" > <div>
<asp:DataList ID="DataList1" Width="100%" runat="server">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" width="100%" class="xian">
<tr>
<td>
<table cellpadding="0" class="style9" 
style="background-image: url('file:///E:/gonghui1/image/l_bg.jpg'); background-repeat: no-repeat">
<tr>
<td align="left" class="Location" width="70%">
<a href="Read.aspx?iid=<%#Eval("iid") %>"> <%#Eval("itile") %></td>
<td width="30%" align="right"><%#Eval("time") %></td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div></marquee>