Home  >  Article  >  Backend Development  >  Implement the automatic scrolling function of GridView

Implement the automatic scrolling function of GridView

零下一度
零下一度Original
2017-06-24 09:17:464008browse

Introduction

The latest winform project uses DevExpress controls, so I have been exploring the use of this set of controls recently. I really admire the power of the entire set of controls, and the code is also simple to write. The customer has a requirement, hoping that the report results can be scrolled regularly on an external large screen. The control we use for this report is the GridControl. The query results cannot be displayed completely on one screen. We add a timer and specify the time for the GridView to automatically scroll and display the information on the next screen.

Colleague’s Implementation

But when I saw the code implemented by my colleague, I felt a little uncomfortable. His approximate code is as follows:

/// <summary>/// 当前的行索引/// </summary>private int currentRowHandle = 0;
/// <summary></summary>
/// 总共含有的行
/// 
private int totalRowCount = 0;
/// <summary>/// 定时器定时事件/// </summary>private void timerScroll_Tick(object sender, EventArgs e)
{      if (currentRowHandle == totalRowCount)
          currentRowHandle = 0;      else  {
          currentRowHandle += 40;          if (currentRowHandle > totalRowCount)
              currentRowHandle = totalRowCount;
      }

      gridView1.FocusedRowHandle = currentRowHandle;
}

In order to realize the automatic scrolling function of GridView, the code introduces 2 fields, and hard-codes the number of rows for each scroll to 40. When the form When scaling with the size of the control, it is possible that 40 rows of data cannot be displayed on one screen, and some data may never be displayed.

My implementation

By consulting the DevExpress manual, I found that GridView already provides methods that can be used directly to achieve the effect of scrolling pages, and the code is as simple as ever, without introducing any fields. The improved code is as follows:

/// <summary>/// 定时器定时事件/// </summary>/// <param>/// <param>private void timerScroll_Tick(object sender, EventArgs e)
{     if (gridView1.IsLastRow)
     {
          gridView1.MoveFirst();
     }     else {
          gridView1.MoveNextPage();
     }
}

Finally send the test results

Implement the automatic scrolling function of GridView

The above is the detailed content of Implement the automatic scrolling function of GridView. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn