Implement the automatic scrolling function of GridView

零下一度
Release: 2017-06-24 09:17:46
Original
4005 people have browsed it

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;
Copy after login
/// <summary></summary>
Copy after login
/// 总共含有的行
Copy after login
/// 
Copy after login
private int totalRowCount = 0;
Copy after login
/// <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;
}
Copy after login

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();
     }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template