Recent

Author Topic: TComboBox in csDropDownList mode  (Read 1269 times)

piola

  • New Member
  • *
  • Posts: 40
TComboBox in csDropDownList mode
« on: June 01, 2019, 10:31:29 am »
Dear all,

I have a problem with TComboBox (Style = csDropDownList). When the selection list is dropped down, how can I distinguish these two cases:

a) The list is closed with RETURN
b) The list is closed with ESCAPE
c) The list is closed by selecting an item with a mouse click.

I can handle case a) because it fires the OnEditingDone event. But I cannot distinguish between b) and c):

- While the list is open, the OnKeyDown event fires for ESCAPE, but it provides Key=0 instead of Key=VK_ESCAPE
- While the list is open, the OnClick event doesn't fire at all
- The difference is that in case b), only the OnCloseUp event fires whilst in case c), first OnSelect and the OnCloseUp fires. But this doesn't help because every other selection change (Cursor up/down) fires OnSelect as well.

I have to distinguish because I want to keep the initial list item when the user cancels the selection with ESCAPE. The combobox is part of a grid (a virtual string tree in this case).

Any help is appreciated :)

wp

  • Hero Member
  • *****
  • Posts: 6499
Re: TComboBox in csDropDownList mode
« Reply #1 on: June 01, 2019, 01:05:37 pm »
I want to keep the initial list item when the user cancels the selection with ESCAPE.
What do you mean with "initial list item"? The Combobox.ItemIndex? It does not change when you press ESCAPE and query it in the OnChange event.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

furious programming

  • Sr. Member
  • ****
  • Posts: 354
  • I click a little.
Re: TComboBox in csDropDownList mode
« Reply #2 on: June 01, 2019, 03:32:08 pm »
@wp: yes, but the OnChange event is fired even when the user choose the same value. It looks like a bug, because if the user choose the same value, it means that nothing changed and the OnChange must not be fired. AFAIR earlier the TComboBox class worked different.

But we can check if the item was changed, testing the new item index with the previous.


@piola: look at the attachment.
Lazarus 2.0.4 with FPC 3.0.4, Windows XP (all 32-bit)

wp

  • Hero Member
  • *****
  • Posts: 6499
Re: TComboBox in csDropDownList mode
« Reply #3 on: June 01, 2019, 04:48:29 pm »
the OnChange event is fired even when the user choose the same value. It looks like a bug, because if the user choose the same value, it means that nothing changed and the OnChange must not be fired. AFAIR earlier the TComboBox class worked different.
The attached demo lists the events related to combobox selection in a memo. I ran it back to Laz 1.0, and even this old version shows the same behavior as Lazarus trunk today: The OnChange event is fired even when the already selected item is selected again. A bug? I don't know, the LCL and VLC are full of these inconsistencies, many of them had to be swallowed to keep Delphi compatibility.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: TComboBox in csDropDownList mode
« Reply #4 on: June 01, 2019, 06:33:52 pm »
what about the property "DroppedDown" it returns true if the list is down.

I think that is what you want?
Number 1 at blue screen app creations!

furious programming

  • Sr. Member
  • ****
  • Posts: 354
  • I click a little.
Re: TComboBox in csDropDownList mode
« Reply #5 on: June 01, 2019, 07:09:31 pm »
I ran it back to Laz 1.0, and even this old version shows the same behavior as Lazarus trunk today: The OnChange event is fired even when the already selected item is selected again.

Hmm… apparently my memory fails me.

Quote
A bug?

Yes and no — depends on what developers wanted to get.

But for me yes, it is a bug or bad idea, because in the current form there is no difference between OnChange and OnSelect and because OnChange is fired even if nothing changed (neither content nor ItemIndex), which is misleading.
« Last Edit: June 01, 2019, 08:04:23 pm by furious programming »
Lazarus 2.0.4 with FPC 3.0.4, Windows XP (all 32-bit)

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: TComboBox in csDropDownList mode
« Reply #6 on: June 01, 2019, 09:55:33 pm »
To Delphi specs.. OnChange only fires if the text in the EDIT box portion changes, this also means while user is
editing it should also change.

 The onSelect/Change is only suppose to fire when the itemIndex changes and there is a flag passed  if memory serves
to report if it was done via user or code.

 There a report on this before but I don't know where it went.
Number 1 at blue screen app creations!

ϻαϻɾΣɀО

  • Jr. Member
  • **
  • Posts: 54
  • MaMrEzO
Re: TComboBox in csDropDownList mode
« Reply #7 on: June 02, 2019, 09:40:12 pm »
Dome details missed?
I have tested your situation, Linux-Amd64, GTK2, Lazarus 3.3., LCL 2.1.0.

I can't see what you guys say.
In csDropDownList on[Change/Selected] just fires when selecting new item!
Its seems a platform/widgetset problem, not LCL/Lazarus ones!

There is the log of combobox (csDropDown) activity:
And for note, There are a pair of ComboBox1EditingDone, one of them raise on opening(DropDown) and the other one fires for closing comobox.
Code: [Select]
ComboBox1EditingDone, ItemIndex: -1 //Open by click
ComboBox1EditingDone, ItemIndex: -1 //Close, Click inside combobox
ComboBox1EditingDone, ItemIndex: -1 //Open Alt+Down
ComboBox1EditingDone, ItemIndex: -1 //Close by Esc
ComboBox1EditingDone, ItemIndex: -1 //Open by click
ComboBox1Change, ItemIndex: 0 //Selecting first Item On The List
ComboBox1Select, ItemIndex: 0 //Selecting first Item On The List
ComboBox1EditingDone, ItemIndex: 0 //Close, Selecting first Item On The List
ComboBox1EditingDone, ItemIndex: 0 //Open
ComboBox1EditingDone, ItemIndex: 0 //Close, Click selected item again(no onChange/onSelect fired)
ComboBox1EditingDone, ItemIndex: 0 //Opne
ComboBox1EditingDone, ItemIndex: 0 //Pick Selected item with arrow keys and hit Enter (no onChange/onSelect fired)
ComboBox1EditingDone, ItemIndex: 0 //Open
ComboBox1Change, ItemIndex: 1 //Select second Item
ComboBox1Select, ItemIndex: 1 //Select second Item
ComboBox1EditingDone, ItemIndex: 1 //Close Select second Item
ComboBox1Change, ItemIndex: -1 //Start typing(Something not on the list, No what you type, even exist item, ItemIndex will be -1)
ComboBox1Change, ItemIndex: -1 //Fires on every key(char),insertin or removing(BackSpc/Del)
ComboBox1Change, ItemIndex: -1
ComboBox1Change, ItemIndex: -1
ComboBox1Change, ItemIndex: -1
ComboBox1Change, ItemIndex: -1
ComboBox1EditingDone, ItemIndex: -1 //Lost focus

In my case (csDropDown) onChange fires on changing the selected item or typing new value! and onSelect fires for a new select item(something except last select one)
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

piola

  • New Member
  • *
  • Posts: 40
Re: TComboBox in csDropDownList mode
« Reply #8 on: June 02, 2019, 10:26:43 pm »
I can't see what you guys say.

And can you distinguish between closing by ESC from closing by Mouse selection?

piola

  • New Member
  • *
  • Posts: 40
Re: TComboBox in csDropDownList mode
« Reply #9 on: June 02, 2019, 10:30:10 pm »
What do you mean with "initial list item"? The Combobox.ItemIndex? It does not change when you press ESCAPE and query it in the OnChange event.

Ok, maybe my original post was not clear. Suppose we have selectable items A, B, C, D, E. Before entering the cell and opening the drop-down-list, let item B be selected. Now the user opens the drop-down-list, scrolls around (either with keyboard or with mouse, it doesn't matter), and finally closes the list with ESC. In this case, item B should become the "active" item again.

The other case is that the user scrolls around and selects item E by mouse-click. Now, of course, item E should become active.

But I haven't found a way yet to reliably distinguish these two cases.

Edit: The problem is, that while the list is open and one presses RETURN, the OnEditingDone event is fired, but it ain't if selecting an item by mouse-click. In This case, the list is closed just the same way it is closed with ESC.
« Last Edit: June 02, 2019, 10:31:52 pm by piola »

ϻαϻɾΣɀО

  • Jr. Member
  • **
  • Posts: 54
  • MaMrEzO
Re: TComboBox in csDropDownList mode
« Reply #10 on: June 03, 2019, 06:37:10 am »
As I say before, There is no onEditingDone while(csDropDownList) style! Just on[chang/selected] and cause of another item selection.
1.You dont tell us your platform/widgetset.
2.onEditiondone on my platform, linux,gtk2/lcl2.1 raise with csDropDown style
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

piola

  • New Member
  • *
  • Posts: 40
Re: TComboBox in csDropDownList mode
« Reply #11 on: June 03, 2019, 09:25:59 am »
Yes, there is OnEditingDone with csDropDownList, but only when using RETURN for selection.

My platform is i386 with Win32 widgetset.

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: TComboBox in csDropDownList mode
« Reply #12 on: June 03, 2019, 01:44:58 pm »
if you are in a jam you can do this..

Form1.KeyPreview := True;
Form1.LastComboKeyPressed:WOrd;
Code: Pascal  [Select]
  1. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  2.   );
  3. begin
  4.   if ComboBox1.DroppedDown Then LastComBokeyPressed := Key Else
  5.     LastComBoKeyPressed := 0;
  6. end;                                                
  7.  
Code: Pascal  [Select]
  1. procedure TForm1.ComboBox1CloseUp(Sender: TObject);
  2. begin
  3.   If lastComBoKeyPressed = VK_ESCAPE then Beep;
  4. end;                                                        
  5.  
Number 1 at blue screen app creations!

piola

  • New Member
  • *
  • Posts: 40
Re: TComboBox in csDropDownList mode
« Reply #13 on: June 03, 2019, 06:08:35 pm »
if you are in a jam you can do this..

I already had that in mind, too, but I think it might be complicated. The ComboBox is dynamically created and would require references in both directions (i.e. combobox would need to know the main form, and the main would need to be informed about whether or not a combobox is currently active).

But if there is no other solution, I will have to try.

However, I still don't understand why the combobox doesn't get the Key=VK_ESCAPE information in its OnKeyDown event?

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: TComboBox in csDropDownList mode
« Reply #14 on: June 03, 2019, 06:25:03 pm »
It does get it, it just comes in after the list closes.

While the list is dropped down only few key strokes go to it.

A combobox is a combination of two controls, a EDIT and Listbox.

You can trap the key messages within the control itself...

If I have time I'll show a class hack that may work...
Number 1 at blue screen app creations!