datagridview 如何循环滚动显示

 datagridview循环滚动显示

首先设置dataGridView的SelectionMode值为FullRowSelect,
MultiSelect值为false.
其次记录不要太少.因为记录太少的时候,FirstDisplayedScrollingRowIndex会一直为0.对其进行赋值等操作

都会无效

要实现循环滚动,须添加计时器事件,计时器代码如下:

 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;

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值