Winform datagridview wheel control event

Source: Internet
Author: User

 

  ///   <Summary>  
3 /// Add a scroll wheel event to the datagridview
4 /// </Summary>
5 /// <Param name = "datagridview1"> </param>
6 Public Static Void Bindmousewheel (system. Windows. Forms. datagridview datagridatagri1)
7 {
8 Datagridview1.mousewheel + = New System. Windows. Forms. mouseeventhandler (maid );
9 Datagridview1.tabindex = 0 ; // Focus
10 }
11
12 Static Void Datagridview#mousewheel ( Object Sender, system. Windows. Forms. mouseeventargs E)
13 {
14 Datagridview datagridatagri1 = Sender As Datagridview;
15 Try
16 {
17 If (Maid ! = Null )
18 {
19 Datagridviewcell DVC = Datagridview1.currentcell;
20 Int Ri = DVC. rowindex;
21 Int Ci = DVC. columnindex;
22 If (E. Delta > 0 ) // Up
23 {
24 If (Ri > 0 )
25 {
26 DVC = Datagridview1.rows [ri - 1 ]. Cells [CI];
27 Datagridview1.currentcell = DVC;
28 }
29 }
30 Else
31 {
32 If (Ri < Datagridview1.rows. Count - 1 )
33 {
34 DVC = Datagridview1.rows [ri + 1 ]. Cells [CI];
35 Datagridview1.currentcell = DVC;
36 }
37 }
38 }
39 }
40 Catch
41 {
42 Return ;
43 }
44 }

 

 

 

 

 

 

Reference: http://archive.cnblogs.com/a/1768664/

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.