ItemSelectionChanged Event

The place for threads about TimoSoft ExplorerListView.
User avatar
Mex
Captain
Posts: 129
Joined: 24 Sep 2009, 19:47

ItemSelectionChanged Event

Post by Mex » 05 Jun 2010, 10:38

Hi

ItemSelectionChanged is rised twice, is this correct?
1) Previous item
2) New item


BR;
Meelis

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: ItemSelectionChanged Event

Post by TiKu » 05 Jun 2010, 14:49

Yes, that's correct, because the selection state of both items changes.
Maybe you are looking for the CaretChanged event?
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

User avatar
Mex
Captain
Posts: 129
Joined: 24 Sep 2009, 19:47

Re: ItemSelectionChanged Event

Post by Mex » 05 Jun 2010, 20:10

Ok, the soluton is in ItemSelectionChanged event
If listItem.Selected Then
'Do what is needed
End If

I can't use CaretChangd event, because when i change list item selection in code and the list has no focus then CaretChanged is not rised.

Danke;
Meelis

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: ItemSelectionChanged Event

Post by TiKu » 05 Jun 2010, 20:35

How do you change the selection in code? Setting the CaretItem property should fire the CaretChanged event.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

User avatar
Mex
Captain
Posts: 129
Joined: 24 Sep 2009, 19:47

Re: ItemSelectionChanged Event

Post by Mex » 05 Jun 2010, 20:43

Im using your control on my own user control, its like a wraper for yor control with additonal events, properties and methods.
My control has a ListIndex property what i can change in code.

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: ItemSelectionChanged Event

Post by TiKu » 05 Jun 2010, 20:56

Well, I assume this ListIndex property is supposed to get/set the caret item, so you should use the CaretItem property. The caret item is the item that has the keyboard focus (if the control has the focus) and usually is selected. Only one item can be the caret item. The ListViewItem.Selected property and the ItemSelectionChanged event have little to do with the caret item. They refer to the item's selection state, i. e. whether it is selected or not. An item is selected if it has a blue background (okay, that's not necessarily correct, but you get the idea). An item that is selected is not necessarily the caret item. In multi-selection mode many items can be selected, but still there's only one caret item.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

User avatar
Mex
Captain
Posts: 129
Joined: 24 Sep 2009, 19:47

Re: ItemSelectionChanged Event

Post by Mex » 05 Jun 2010, 21:03

Well, I assume this ListIndex property is supposed to get/set the caret item, so you should use the CaretItem property.
Yes and no. When ListView has no focus then i can't use CaretItem

Let' say you have texbox, button and listview on the form. Listview has 10 items and textbox has a focus.
When youy click button you must change listviews "listindex" but the listview has no focus then ItemSelectionChanged is rised but CaretChanged not.

I'll try to post a sample with my control :)

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: ItemSelectionChanged Event

Post by TiKu » 05 Jun 2010, 21:11

I just did a test (WIndows 7 x64 with themes):

Code: Select all

Set ExLvw.CaretItem = ExLvw.ListItems(3)
This code causes the CaretChanged event to be raised, even if the list view doesn't have the focus. The only situation in which the event is not raised, is when item 3 already was the caret item.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

User avatar
Mex
Captain
Posts: 129
Joined: 24 Sep 2009, 19:47

Re: ItemSelectionChanged Event

Post by Mex » 05 Jun 2010, 21:18

Ok now i understant, we have just different approach :)

In my control, when i set the ListIndex property i use;
Public Property Let ListIndex(ByVal value As Long)
If theList.ListItems.Count > 0 Then
If value > theList.ListItems.Count - 1 Then
value = 0
End If
theList.ListItems(value).Selected = True
Let MyListIndex = value
End If
End Property
Attachments
sample.zip
(44.35 KiB) Downloaded 325 times

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: ItemSelectionChanged Event

Post by TiKu » 05 Jun 2010, 21:24

What is this useful for? You have a property that can be set to exactly 1 list item. It will select this item. What's with the other selected items? Or are you in single selection mode? If you are in single selection mode, why would you want to select an item without making it the caret item?
Of course the CaretChanged event is not raised, if you change an item's selection state, because changing an item's selection state doesn't change the item's caret state.

After trying your sample, I'm convinced more than before that what you really want to use are the CaretChanged event and the CaretItem property.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

User avatar
Mex
Captain
Posts: 129
Joined: 24 Sep 2009, 19:47

Re: ItemSelectionChanged Event

Post by Mex » 05 Jun 2010, 21:27

What is this useful for? You have a property that can be set to exactly 1 list item. It will select this item. What's with the other selected items? Or are you in single selection mode? If you are in single selection mode, why would you want to select an item without making it the caret item?
Of course the CaretChanged event is not raised, if you change an item's selection state, because changing an item's selection state doesn't change the item's caret state.
Yup, im not using MultiSelect.
So better is to use CaretItem?

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: ItemSelectionChanged Event

Post by TiKu » 05 Jun 2010, 21:29

Yes, see my edit in the previous post.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

User avatar
Mex
Captain
Posts: 129
Joined: 24 Sep 2009, 19:47

Re: ItemSelectionChanged Event

Post by Mex » 05 Jun 2010, 21:36

ok, thank you for your response and for being so patient with me :)


Meelis

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: ItemSelectionChanged Event

Post by engee30 » 25 Feb 2013, 21:31

Hello

Is there a quick way of getting the number of all selected items? I've got over 300.000 items in my Listview and when I want to get the number (in this case in the MouseUp event), it lags a bit before I get it displayed in a Label.

Pete

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: ItemSelectionChanged Event

Post by TiKu » 26 Feb 2013, 00:31

Hi,

try this:

Code: Select all

  Dim col As ListViewItems

  Set col = ExLVwU.ListItems
  col.FilterType(FilteredPropertyConstants.fpSelected) = FilterTypeConstants.ftIncluding
  col.Filter(FilteredPropertyConstants.fpSelected) = Array(True)
  Debug.Print col.Count
Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

Post Reply