[Hope to create] Let DBGrid support browsing data with the scroll wheel and remove vertical scroll bars!

Source: Internet
Author: User

DBGrid does not support scroll by the middle mouse. Sometimes we want to remove the horizontal scroll bar. Let's create a custom DBGrid component by ourselves!

CodeAs follows:
Unit addmsgdbgrid;

Interface

Uses
Windows, sysutils, messages, classes, controls, grids, dbgrids;

Type
Taddmsgdbgrid = Class (TDBGrid)
Protected // Add a new 'scroll wheel message'
Procedure wmmousewheel (VAR message: tmessage); message wm_mousewheel;
Procedure paint; override; // override the paint to remove the 'horizontal scroller'
End;

Procedure register;
Implementation

Procedure register;
Begin
Registercomponents ('gencheng', [taddmsgdbgrid]);
End;

{Taddmsgdbgrid}

Procedure taddmsgdbgrid. wmmousewheel (VAR message: tmessage );
VaR
Scrolldown: Boolean;
Begin
Scrolldown: = short (message. wparamhi) <0; // The short function is in Windows
If assigned (self. datasource) and assigned (self. datasource. dataset) and self. datasource. dataset. Active then
If scrolldown then
Self. datasource. dataset. moveBy (1) // or self. datasource. dataset. Next;
Else
Self. datasource. dataset. moveBy (-1); // or self. datasource. dataset. Prior;
End;

Procedure taddmsgdbgrid. paint;
Begin
Setscrollrange (self. Handle, sb_horz, 0, 0, false); // remove the horizontal scroll bar
Inherited paint;
End;

End.

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.