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.