DataGrid supports scroll record with scroll wheel

Source: Internet
Author: User

Http://www.mndsoft.com/blog/article.asp? Id = 901

In this site VB source code "Data Grid drop-down list box controls" (link address: http://www.mndsoft.com/blog/article.asp? In id = 214), the user taomaintao prompts that the scroll wheel and mouse are supported.CodeSome API code is intended to support scroll wheel, but it may not be added by the author later. Based on this, I found a solution (from the Network), taomaintao
You can follow the steps below to modify it.

First, set the "select box style" in the "split" attribute of the DataGrid to 3, that is, to highlight and select the entire row, and add the following code to support it, as long as you move the mouse focus on the Grid Control and scroll the mouse pulley, the grid scroll bar will automatically scroll.

If you need more smooth scrolling and custom scrolling methods, I still have a code to send to you. Study it by yourself.

Example operation method:
Write the following code to the public module:

'Support scroll mouse API ---------------------------------
Public const gwl_wndproc = (-4)
Public const wm_command = & h111
Public const wm_mbuttondown = & h207
Public const wm_mbuttonup = & h208
Public const wm_mousewheel = & h20a

Public oldwinproc as long
Public declare function setwindowlong lib "USER32" alias "setwindowlonga" (byval hwnd as long ,_
Byval nindex as long, byval dwnewlong as long) as long

Public declare function callwindowproc lib "USER32" alias "callwindowproca" (byval lpprevwndfunc as long ,_
Byval hwnd as long, byval MSG as long, byval wparam as long, byval lparam as long) as long

Public declare function getwindowlong lib "USER32" alias "getwindowlonga" (byval hwnd as long ,_
Byval nindex as long) as long
Public Function flexscroll (byval hwnd as long, byval wmsg as long, byval wparam as long, byval lparam as long) as long
'The scroll Yu of the scroll wheel is supported.
Select case wmsg
Case wm_mousewheel
Select case wparam
Case-7864320 'roll down
Sendkeys "{pgdn }"
Case 7864320 'roll up
Sendkeys "{pgup }"
End select

End select
Flexscroll = callwindowproc (oldwinproc, hwnd, wmsg, wparam, lparam)
End Function
'Support scroll mouse API ---------------------------------


'Write the following code to the gotfocus event of the table control.
Private sub control name_gotfocus ()
Oldwinproc = getwindowlong (Me. hwnd, gwl_wndproc)
Setwindowlong me. hwnd, gwl_wndproc, addressof flexscroll
End sub

'Write the following code to the lostfocus event of the table control.
Private sub control name_lostfocus ()
Setwindowlong me. hwnd, gwl_wndproc, oldwinproc
End sub

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.