Recent

Author Topic: TListBox. Drop down multiselection  (Read 633 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
TListBox. Drop down multiselection
« on: November 03, 2025, 04:21:46 pm »
I have a list box. MultiSelect is set to true. OnKeyDown event looks like this:
Code: Pascal  [Select][+][-]
  1. procedure TFFileList.lbFilesKeyDown(Sender: TObject; var Key: Word;
  2.   Shift: TShiftState);
  3. var
  4.   i: SizeInt;
  5. begin
  6.   lbFiles.OnKeyDown:= nil;
  7.  
  8.   case Key of
  9.   VK_RETURN: ModalResult:= mrOK;
  10.   VK_ESCAPE: ModalResult:= mrCancel;
  11.   else if Key >= Byte('A') then begin
  12.     i:= Key - Byte('A');
  13.     if i < lbFiles.Count then
  14.       lbFiles.Selected[i]:= not lbFiles.Selected[i];
  15.   end;
  16.   end;
  17.  
  18.   lbFiles.OnKeyDown:= @lbFilesKeyDown;
  19. end;
The idea is next – when I press for example 'A' key the first element in list box should be selected (or deselected), so I can select on deselect multiple items. Instead it only selects the last one I pressed and deselect all other choises. What I am doing wrong?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

bytebites

  • Hero Member
  • *****
  • Posts: 778
Re: TListBox. Drop down multiselection
« Reply #1 on: November 03, 2025, 05:31:09 pm »
Form.keypreview:=true?

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: TListBox. Drop down multiselection
« Reply #2 on: November 03, 2025, 05:33:36 pm »
It works. Thank you.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: TListBox. Drop down multiselection
« Reply #3 on: November 03, 2025, 05:57:15 pm »
It strange. Whan I first time compiled with KeyPreview=True multiselction worked as I want. When I compiled at second time it start work as I initially described.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: TListBox. Drop down multiselection
« Reply #4 on: November 03, 2025, 07:14:52 pm »
I tryied to reproduce this effect on a smaller project. But in smaller project it works as expected.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: TListBox. Drop down multiselection
« Reply #5 on: November 03, 2025, 07:19:23 pm »
I tryied to reproduce this effect on a smaller project. But in smaller project it works as expected.
Sigh, we can't debug for you what else you are doing wrong without seeing all the sourcecode that reproduces the issue.
By  now, you know that!.

When one of the helpers on this forum see all sourcecode the problem would have been solved.
Most helpers can be sent a private message.
« Last Edit: November 03, 2025, 07:23:00 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: TListBox. Drop down multiselection
« Reply #6 on: November 03, 2025, 07:38:16 pm »
Here is the project. It require sqlite3.dll.

When program is opened press "D". Will be opened form FFileList. In this form occur the problem.
« Last Edit: November 03, 2025, 08:22:43 pm by LemonParty »
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

bytebites

  • Hero Member
  • *****
  • Posts: 778
Re: TListBox. Drop down multiselection
« Reply #7 on: November 03, 2025, 11:16:49 pm »
Add key:=#0 at the end of the keydown event.

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: TListBox. Drop down multiselection
« Reply #8 on: November 03, 2025, 11:42:51 pm »
It helped. Thank you.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

 

TinyPortal © 2005-2018