自动滚动网格视图 [英] scroll the grid view automatically

查看:50
本文介绍了自动滚动网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自动滚动c#(Windows应用程序)中的datagridview,我可以这样做吗??????? plz如果有任何想法

scrolling the datagridview in c#(windows app)automatically,can i do this???????plz if any idea

推荐答案

看看此StackOverflow Q/A 如何以编程方式滚动winforms控件? [^ ]
Take a look at this StackOverflow Q/A How do I programmatically scroll a winforms control?[^]


您是否尝试过添加面板,然后固定其大小,然后使其可滚动?然后将您的datagridview放在里面?试试这个.我相信这会解决您的问题.

问候,
爱德华
Have you tried adding a panel, then having its size fixed, then making it scrollable?? then placing your datagridview inside it?? Try this one. I believe this will solve your problem.

Regards,
Eduard


1.将计时器添加到您的Windows窗体项目.将其间隔"属性设置为所需的毫秒数.

一个.创建一个整数变量,并将其值设置为最初要显示在DataGridView顶部的行的索引.
1. Add a Timer to your Windows Form project. Set its ''Interval property to the value in milliseconds you want.

a. create an integer variable, and set its value to the index of the row you want initially displayed at the top of the DataGridView.
int firstRowDisplayed = 200;

b.创建一个整数变量,其值是总行数-1.

b. create an integer variable whose value is total number of rows -1.

int lastRowIndex = dataGridView1.Rows.Count -1;

2.

dataGridView1.FirstDisplayedScrollingRowIndex  = firstRowDisplayed;

3.使用DataGridView的整数FirstDisplayedScrollingRowIndex属性(具有并设置)来确保要显示的初始行是可见的.以任意方式触发计时器(通过Button EventHandler,在Form Load中或通过Shown EventHandler,等等).

4.在计时器代码"中,勾选"Tick EventHandler:

一个.进行正确的操作以增加firstRowDisplayed变量并选择DataGridView中最顶部的可见行.增量实际上将向上"滚动DataGridView.

5.那么,如何使它向上移动,直到最后一行位于顶部,然后又向下直到第一行位于顶部?

一个.留给您找出来:)

提示:具有一个布尔变量,您可以在"Tick EventHandler"中使用它,根据比较当前值是否等于最后一行来确定是递增还是递减"firstRowDisplayed"(在这种情况下,firstRowDisplayed == lastRowIndex),并且您想开始滚动回顶部,或者(如果向上移动)等于零,那么在这种情况下,您要开始向底部滚动.

6.规划如何确定何时停止动画",这时您将禁用计时器.

3. trigger the Timer in whatever way you wish (by Button EventHandler, in a Form Load or Shown EventHandler, whatever).

4. in the Timer Code ''Tick EventHandler:

a. do the right thing to increment the firstRowDisplayed variable and select the topmost visible row in the DataGridView. Incrementing will essentially scroll the DataGridView "up."

5. So, how do I make it go up, until the last row is at the top, and then back down until the first row is at the top ?

a. left for you to figure out :)

Hint: have a boolean variable which you will use inside the ''Tick EventHandler to determine whether you increment or decrement ''firstRowDisplayed based on comparing if its current value is equal to the last row (in which case firstRowDisplayed == lastRowIndex), and you the want to start scrolling back to the top, or (if moving up) is equal to zero, in which case you to start scrolling back towards the bottom.

6. plan for how you wish to determine when the "animation" will stop, at which point you will disable the Timer.


这篇关于自动滚动网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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