2008. szeptember 12., péntek

How select first item in ListView with use key TAB


Problem/Question/Abstract:

When I hand over focus with key TAB to ListView, ListView not select first item. How on it?

Answer:

We have two ListView components. First component with name ListView1 contains two events.


procedure TForm1.ListView1Enter(Sender: TObject);
begin
  HookHandle := SetWindowsHookEx(WH_KEYBOARD, @MsgHook, 0, GetCurrentThreadID);
end;

procedure TForm1.ListView1Exit(Sender: TObject);
begin
  UnHookWindowsHookEx(HookHandle);
end;


Second component with name ListView2 is activate with procedure MsgHook.


function MsgHook(Code: Integer; WParam: WPARAM; LParam: LPARAM): Integer; stdcall;
const
  KeyTAB: Integer = 983041;
begin
  if (Code = HC_ACTION) then
  begin
    if LParam = KeyTAB then
    begin
      frmMain.lsvCCM.SetFocus;
      SendMessage(Form1.ListView2.Handle, WM_KEYDOWN, VK_DOWN, 1);

      Result := -1;
      Exit;
    end;
  end;

  Result := CallNextHookEx(HookHandle, Code, WParam, LParam);
end;

Nincsenek megjegyzések:

Megjegyzés küldése