| |

VerySource

 Forgot password?
 Register
Search
View: 782|Reply: 1

Use the following code to support the mouse wheel in DBGRID, but after selecting multiple records, the focus will be los

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-20 01:20:01
| Show all posts |Read mode
procedure TForm_dbgrid.ApplicationEvents1Message (var Msg: tagMSG;
  var Handled: Boolean);
begin
     if (DBGrid1.Focused) And (Msg.message = WM_MOUSEWHEEL) then
        begin
            if Msg.wParam> 0 then
                SendMessage (DBGrid1.Handle, WM_KEYDOWN, VK_UP, 0)
            else
                SendMessage (DBGrid1.Handle, WM_KEYDOWN, VK_DOWN, 0);
            Handled: = True;
        end;

end;

===== The above code implements a mouse wheel that can be used in DBGRID, but after selecting multiple records, the selected records are all lost (the focus will not be lost with the drop-down bar), how to solve it?
Reply

Use magic Report

0

Threads

25

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-5-10 11:15:01
| Show all posts
The problem is that you sent a WM_KeyDown message to DBGRID, that is, you pressed the up and down keys on the DBGrid. Of course this will happen. Just change the news, and that's it.

procedure TForm_DBGrid.ApplicationEvents1Message (var Msg: tagMSG;
  var Handled: Boolean);
var
  MsgScroll: TWMScroll;
begin
  if (DBGrid1.Focused) and (Msg.message = WM_MOUSEWHEEL) then
  begin
    MsgScroll.Msg: = WM_VScroll;
    if Msg.wParam> 0 then
      MsgScroll.ScrollCode: = SB_LINEUP
    else
      MsgScroll.ScrollCode: = SB_LINEDOWN;
    DBGrid1.Dispatch (MsgScroll);
    Handled: = True;
  end;
end;
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list