DataGridView FirstDisplayedScrollingRowIndex属性如何改变?

chyocean 2008-01-24 11:06:27
我想让DataGridView 中的数据自动滚动
目前是想在计时器的事件中,改变FirstDisplayedScrollingRowIndex 的值.
下面是该计时器事件的代码:
private void timer1_Tick(object sender, EventArgs e)
{
//dgvcasebystreet为一个DataGridView 控件
int index = this.dgvcasebystreet.FirstDisplayedScrollingRowIndex;
index++;
this.dgvcasebystreet.FirstDisplayedScrollingRowIndex = index;
if (this.dgvcasebystreet.FirstDisplayedScrollingRowIndex > this.dgvcasebystreet.RowCount-1)
{
this.dgvcasebystreet.FirstDisplayedScrollingRowIndex = 0;
}
}
但是在调试时发现该FirstDisplayedScrollingRowIndex的值一直没有变化,且一直为0.
请问是不是要设置DataGridView 的什么属性,才能改变FirstDisplayedScrollingRowIndex的值?
...全文
1166 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
adandelion 2008-03-19
  • 打赏
  • 举报
回复
谢谢分享
chyocean 2008-01-29
  • 打赏
  • 举报
回复
我现在是在子窗体中,想实现计时器事件,因而FirstDisplayedScrollingRowIndex 的值没法改变.
有朋友碰到国类似的情况么.

注:子窗体嵌在父窗体中.
chyocean 2008-01-29
  • 打赏
  • 举报
回复
当数据太少的时候,
this.dgvcasebystreet.FirstDisplayedScrollingRowIndex++; 这句话是没有作用的.
这是我一开始碰到的问题.
感谢"平民百姓"等朋友的回帖!
chyocean 2008-01-29
  • 打赏
  • 举报
回复
to:平民百姓
你说的正是我遇到的情况.谢谢!问题已经解决
下面是我最终的计时器事件的代码:
这段代码能够实现循环滚动.
private void timer1_Tick(object sender, EventArgs e)
{ //dgvcasebystreet为DataGridVew控件
int index = this.dgvcasebystreet.FirstDisplayedScrollingRowIndex;
this.dgvcasebystreet.Rows[index].Selected = true;
this.dgvcasebystreet.FirstDisplayedScrollingRowIndex++;
//如果数据太少.就不滚动
if (index == this.dgvcasebystreet.FirstDisplayedScrollingRowIndex)
{
return;
}
//将刚才定位的数据插入到dtSource的末尾.这是为了实现循环滚动.
dtSource.ImportRow(dtSource.Rows[index]);
//rowCount为记录总数
if (this.dgvcasebystreet.FirstDisplayedScrollingRowIndex > rowCount - 1)
{
//初始时,将数据取出同时放在dtSource 与dtTmpSource中,
//现在dtSource中,已增加了很多数据.
//因而在所有原数据都遍历完,开始下一次遍历时,将原数据覆盖现在的dtSource ;
dtSource = dtTmpSource;
this.dgvcasebystreet.FirstDisplayedScrollingRowIndex = 0;
}

}
//下面注释掉代码,只是用来说明程序中是如何绑定数据的.
//BindingSource bindSrc = new BindingSource();
//bindSrc.Clear();
//bindSrc.DataSource = dtSource;//该dtSource为存放数据的dataTable对象
//this.dgvcasebystreet.DataSource = bindSrc;
将我最后的代码贴出来,和大家一起分享.

感谢回答问题的每一位朋友!
北京的雾霾天 2008-01-29
  • 打赏
  • 举报
回复
滚动条是不是因为记录太少没有显示出来?
九章落地 2008-01-29
  • 打赏
  • 举报
回复
FirstDisplayedScrollingRowIndex如下面使用便可以:
this.dgvcasebystreet.FirstDisplayedScrollingRowIndex+=1;

当然,楼主上面的代码,也看不出问题来.

你检查下你的代码,看Timer是否有触发,或其它地方有设置FirstDisplayedScrollingRowIndex属性.
chyocean 2008-01-28
  • 打赏
  • 举报
回复
有没有知道这个问题啦
chyocean 2008-01-24
  • 打赏
  • 举报
回复
我想让该DataGridView自动滚动,
网上也有很多改变FirstDisplayedScrollingRowIndex属性的例子,
但是我自己用的时候怎么就改变不了呢.
郁闷阿
he_8134 2008-01-24
  • 打赏
  • 举报
回复
从那个属性的名称可以揣摩出那个属性是不会变的....应该是第一次显示该控件的时候选中项的index....

你要达到什么目的?找错对象了吧?

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧