Link to home
Start Free TrialLog in
Avatar of Leo01010101
Leo01010101

asked on

BCB6 DBGrid Vertical ScrollBar shouldn't change selected record

Hi, I want to set DBGrid to not allow a vertical ScrollBar to change selected record. Is it possible?
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leo01010101
Leo01010101

ASKER

Yes, I did it and it was working. But I'm looking now for solution where scroll-bar will work and change position of first displayed record but without changing selection.
Then you can make inherited dbgrid with WMVScroll message method overrided:
type
  TMyDBGrid = class(TDBGrid)
  private
    procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
  end;

...

implementation

procedure TMyDBGrid.WMVScroll(var Message: TWMVScroll);
begin
  // inherited; //keep commented
end;

Open in new window


... or you can replace WindowProc method where you must ignore TWMVScroll message.
Here is example of how to replace this method...
http://stackoverflow.com/questions/5397158/delphi-drag-drop-with-listview/5397705#5397705
I'm not sure how to implement your code in C++,

I tried to catch WM_SCROLL in this way:

void __fastcall TForm1::FormCreate(TObject *Sender)
{
   Application->OnMessage = AppMessage;
}

void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
{
  if( Msg.message == WM_VSCROLL )
  {
   Handled = true;
  }
}

Open in new window



but it didn't catch this event when I move a vertical scroll bar ( mouse wheel message is catched etc.. ). What could be a reason?