Recent

Author Topic: Prevent collapsing item list of TCheckComboBox  (Read 369 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 700
Prevent collapsing item list of TCheckComboBox
« on: September 14, 2024, 10:25:05 am »
Hi,

I want to be able to select a number of combobox items. Apparently this can be done with a TCheckComboBox.
How do I prevent the list from collapsing after each item selection? I cant find an option for it. And is it possible to create some distance between the items? See attachment, the items are next to each other.
Or is there another component that is better suited for selecting multiple items and if necessary add a new item?

jamie

  • Hero Member
  • *****
  • Posts: 6550
Re: Prevent collapsing item list of TCheckComboBox
« Reply #1 on: September 14, 2024, 04:24:53 pm »
With out subclassing the list window which I am sure is only possible in windows, where you can get the actual list window handle to caption the close event, you can do following. Not sure if this is cross platform either.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckComboBox1KeyDown(Sender: TObject; var Key: Word;
  2.   Shift: TShiftState);
  3. begin
  4.    With TCheckComboBox(Sender) do
  5.    Begin
  6.    IF (Key = VK_Space) Then
  7.     begin
  8.       DroppedDown := true;
  9.     end;
  10.    end;                                  
  11.  
  12.  

This will of course cause the list to close and reopen but at least it should be where you were act before using the space key.

The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12345
Re: Prevent collapsing item list of TCheckComboBox
« Reply #2 on: September 14, 2024, 04:37:56 pm »
Or is there another component that is better suited for selecting multiple items [...]?
The TCheckComboboxEx in the ExCtrls package (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/exctrls/) collapses the dropdown only when [ENTER] or [ESC] are pressed or when an item is double-clicked.

Sieben

  • Sr. Member
  • ****
  • Posts: 325
Re: Prevent collapsing item list of TCheckComboBox
« Reply #3 on: September 14, 2024, 05:06:34 pm »
You might also want to consider a TCheckListBox, which can be viewed as a permanently dropped down list. Drawback is of course that it also permanently consumes space.
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

jamie

  • Hero Member
  • *****
  • Posts: 6550
Re: Prevent collapsing item list of TCheckComboBox
« Reply #4 on: September 14, 2024, 05:39:58 pm »
if you use a data Module and drop a TlistCheckBox on that, you can at any time show that box with the parent set and position set just under what looks like an editbox etc.

This can be shown whenever the edit box becomes focused.

 
The only true wisdom is knowing you know nothing

Hansvb

  • Hero Member
  • *****
  • Posts: 700
Re: Prevent collapsing item list of TCheckComboBox
« Reply #5 on: September 15, 2024, 12:03:56 pm »
Thanks, i will look at the options. For now i parked the idea of using a tcheckedcombobox

 

TinyPortal © 2005-2018