View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0020501||Lazarus||LCL||public||2011-10-17 22:39||2017-04-23 11:23|
|Reporter||eclipticon||Assigned To||Mike Thompson|
|Summary||0020501: Deleting selected item in TListBox.Items does not trigger TListBox.OnSelectionChange|
|Description||When the currently selected item in a TListBox is deleted via AListBox.Items.Delete(AListBox.ItemIndex), the selection disappears and TListBox.ItemIndex becomes -1. OnSelectionChange is not fired, however.|
|Tags||No tags attached.|
|Fixed in Revision|
||@eclipticon, can you test with current trunk ? I think it's fixed few weeks ago.|
Confirmed on win32 widgetset on Win7 Lazarus 1.1 r38083/Fpc 2.6.0
and on Linux GTK2 Lazarus 1.1 r38262 FPC 2.6.0 i386-linux-gtk 2
TListBox.Items.Delete does not update TListBox.ItemIndex.
This will only be updated when GetItemIndex is called.
The WS does not report back (or we do not listen) that an item has been deleted.
We could hook into Items.OnChange to detect such a thing and call DoSelectionChanged, but that sounds a little bit hackish to me.
B.t.w. OnSelectionChanged is called (on Windows at least) every time you click on an item, even if this was already selected.
||B.t.w. How does Delphi behave in this case?|
> We could hook into Items.OnChange to detect such a thing and call
> DoSelectionChanged, but that sounds a little bit hackish to me.
That doesn't work...
||Maybe TListBox should have a hnadler for LM_DELETEITEM message?|
Since Delphi does not seem to have an OnSelectionChange event, here's an interesting question.
If MultiSelect = True should the event be triggerd in the following scenarios?
A with a ListBox with 10 items, Item and Item selected.
Delete(2) (or Delete(0)): visually the same items remain selected, but Item now has become Item (and is selected)
Delete(6): visually the same items remain selected and their indexes remain the same
Delete(4): visually only one item remains selected, one of the selected items was deleted.
Insert(0): visually the selected items remain the same, but their indexes now are +1
Scenario 2: it seems logical to say selection has NOT changed.
Scenario 3: it seems logical to say selection has changed.
Scenario 1: ?
ListBoxOnSelectionChange.zip (2,754 bytes)
I have confirmed the reported bahviour and added a simple test project.
In answer to @Barts question above:
My opinion is No OnSelectionChange should be issued for Scenario 1, 2 & 4. I've confirmed via the test harness that .ItemIndex is generally updated (see below). As the developer manually called the Items.Delete, they have a mechanism to immediately retrieve the new ItemIndex.
However, while developing the test project I uncovered a possibly related issue (still Win32). If MultiSelect := True, and multiple items are selected, then following Items.Delete, TListBox.ItemIndex remains unchanged. (Repeatable in the Test Project by Checking "MutiSelect", multiselecting items 1, 2 & 3, then deleting item 0)
|2011-10-17 22:39||eclipticon||New Issue|
|2011-10-17 22:39||eclipticon||Widgetset||=> Win32/Win64|
|2011-10-17 23:57||Juha Manninen||Relationship added||related to 0020324|
|2011-10-21 09:36||Vincent Snijders||LazTarget||=> 1.2|
|2011-10-21 09:36||Vincent Snijders||Status||new => acknowledged|
|2011-10-21 09:36||Vincent Snijders||Target Version||=> 1.2.0|
|2012-03-17 18:08||Zeljan Rikalo||Note Added: 0057780|
|2012-03-17 18:08||Zeljan Rikalo||Status||acknowledged => feedback|
|2012-07-28 22:17||Bart Broersma||Note Added: 0061273|
|2012-07-28 22:17||Bart Broersma||Status||feedback => confirmed|
|2012-08-17 14:14||Bart Broersma||Note Edited: 0061273|
|2012-10-13 17:11||Bart Broersma||Note Added: 0063130|
|2012-10-13 17:13||Bart Broersma||Note Edited: 0063130|
|2013-11-01 20:27||Bart Broersma||Note Added: 0071087|
|2013-11-01 23:06||Bart Broersma||Status||confirmed => feedback|
|2013-11-17 16:33||Bart Broersma||Note Added: 0071365|
|2013-12-07 15:23||Bart Broersma||Note Added: 0071812|
|2013-12-30 00:46||Bart Broersma||Note Added: 0072092|
|2014-01-05 18:36||Bart Broersma||Note Edited: 0072092||View Revisions|
|2014-01-05 18:37||Bart Broersma||LazTarget||1.2 => 1.4|
|2014-01-05 18:37||Bart Broersma||Target Version||1.2.0 => 1.4|
|2014-09-16 17:07||Mike Thompson||File Added: ListBoxOnSelectionChange.zip|
|2014-09-16 17:14||Mike Thompson||Note Added: 0077304|
|2014-09-16 17:16||Mike Thompson||Note Edited: 0077304||View Revisions|
|2014-09-16 17:55||Mike Thompson||Note Edited: 0077304||View Revisions|
|2014-09-16 18:12||Mike Thompson||Note Edited: 0077304||View Revisions|
|2014-10-09 19:56||Mike Thompson||Assigned To||=> Mike Thompson|
|2014-10-09 19:56||Mike Thompson||Status||feedback => assigned|
|2015-04-27 21:59||Juha Manninen||LazTarget||1.4 => -|
|2015-04-27 22:02||Juha Manninen||Target Version||1.4 =>|
|2017-04-23 11:23||Bart Broersma||Relationship added||related to 0031697|