View Issue Details

IDProjectCategoryView StatusLast Update
0020501LazarusLCLpublic2017-04-23 11:23
Reportereclipticon Assigned ToMike Thompson  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Product Version0.9.30 
Summary0020501: Deleting selected item in TListBox.Items does not trigger TListBox.OnSelectionChange
DescriptionWhen 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.
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetWin32/Win64
Attached Files

Relationships

related to 0020324 closedPaul Ishenin ListBox no call OnSelectionChage when DragMode is dmAutomatic 
related to 0031697 closedZeljan Rikalo TCheckListBox.OnSelectionChange never fires 

Activities

Zeljan Rikalo

2012-03-17 18:08

developer   ~0057780

@eclipticon, can you test with current trunk ? I think it's fixed few weeks ago.

Bart Broersma

2012-07-28 22:17

developer   ~0061273

Last edited: 2012-08-17 14:14

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

Bart Broersma

2012-10-13 17:11

developer   ~0063130

Last edited: 2012-10-13 17:13

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.

Bart Broersma

2013-11-01 20:27

developer   ~0071087

B.t.w. How does Delphi behave in this case?

Bart Broersma

2013-11-17 16:33

developer   ~0071365

> 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...

Bart Broersma

2013-12-07 15:23

developer   ~0071812

Maybe TListBox should have a hnadler for LM_DELETEITEM message?

Bart Broersma

2013-12-30 00:46

developer   ~0072092

Last edited: 2014-01-05 18:36

View 2 revisions

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[1] and Item[4] selected.

Scenario 1:
Delete(2) (or Delete(0)): visually the same items remain selected, but Item[4] now has become Item[3] (and is selected)

Scenario 2:
Delete(6): visually the same items remain selected and their indexes remain the same

Scenario 3:
Delete(4): visually only one item remains selected, one of the selected items was deleted.

Scenario 4:
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: ?

Mike Thompson

2014-09-16 17:07

developer  

Mike Thompson

2014-09-16 17:14

developer   ~0077304

Last edited: 2014-09-16 18:12

View 4 revisions

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)

Issue History

Date Modified Username Field Change
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