先强调一下,是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个项显示出来

解决方案 »

  1.   

    ListViewItem.EnsureVisible方法应该可以达到你的要求,参考MSDN。
    http://msdn.microsoft.com/zh-cn/library/system.windows.forms.listviewitem.ensurevisible.aspx
      

  2.   

    lvData.EnsureVisible(899)
    or
    lvData.EnsureVisible(lvData.Index)
      

  3.   

    ListView: EnsureVisible
    DataGridView:dataGridView1.FirstDisplayedScrollingRowIndex
      

  4.   

    DataGridView这样就可以了显示某一行了,,滚动条自动滚动  dataGridView1.CurrentCell = dataGridView1.Rows[899].Cells[0];//选中第900行
      

  5.   

    实现自动滚动,你只要把它的当前index设置为最大的一个就可以了比如以list为例子,List.CurrentIndex=List.Items.Count()-1;
    代码随手打的,可能不太对,但是思路是这个。我做TCP通信的时候就这样写的
      

  6.   

    楼主可以换用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>
      

  7.   


    偶在第一句话里就强调了,我用的是 WinForm 控件,不是asp.net控件
    还好您老人家不是在参加高考,否则怎么得的鸭蛋都不知道