By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Multiselect in a listview (VB6)

P: 36
Hi
I have enabled multiselect in my listview. My problem is that when I click inside the listview but not on a item
Expand|Select|Wrap|Line Numbers
  1. .
  2. Set oListItem = ListView3.HitTest(X, y)
  3. oListItem is nothing. This is ok. So i set all the selected property in the listview 
  4.  
to false
Expand|Select|Wrap|Line Numbers
  1. dim i as integer
  2. for i=1 to ListView1.ListItems.Count
  3. ListView1.ListItems.item(index).Selected = False
  4. next
  5.  
My problem is the following
lets say I have 10 items in my list. I click on the first item
then i click below all 10 items select the 3 last items (my clicking and dragging the mouse)
What happends now is that the last 3 is selected but also the first item.
how can I avoid this?
I only want the last 3 to be selected

help is appreciated
Jul 4 '07 #1
Share this Question
Share on Google+
13 Replies


P: 36
I should also mention that there are 2 differnt listviews;

Under components I have used both the one under
Microsoft Windows Common Controls 5 (SP2)
Microsoft Windows Common Controls 6 (SP4)

there behave different
One of them has the behavour I want but it doesnt allow you to set the colour of an item like
Expand|Select|Wrap|Line Numbers
  1. Listview.Listitems.Item(2).forecolour = xxx
If anyone knows how to solve this plz help
Jul 4 '07 #2

Expert 5K+
P: 8,434
Sorry if this is an obvious one, but are you sure the index doesn't start at 0, rather than 1?

Oh, and does this problem only occur with the first item, or any/all of them?
Jul 5 '07 #3

P: 36
Sorry if this is an obvious one, but are you sure the index doesn't start at 0, rather than 1?

Oh, and does this problem only occur with the first item, or any/all of them?

Hi!
Yes happends for all. The choice doesnt come up in the intellisence... :(
Jul 5 '07 #4

Expert 5K+
P: 8,434
Yes happends for all. The choice doesnt come up in the intellisence... :(
What choice? You mean the forecolor? I was only talking about the selection problem, not forecolor. My point was that if the index started at 0, and you were only resetting them starting at 1, you might have simply missed the first (or "zeroth") one.

If I can just recap for a moment, I believe the basic problem is that when your code sets .Select to false (in the Common Controls 6 version), it is not de-selecting the items - is that correct?
Jul 6 '07 #5

P: 36
What choice? You mean the forecolor? I was only talking about the selection problem, not forecolor. My point was that if the index started at 0, and you were only resetting them starting at 1, you might have simply missed the first (or "zeroth") one.

Sorry this was not a problem.. My point here is that the listiview in Common Controls 5 doesnt support setting eg index forecolours.. So I cant used this.


If I can just recap for a moment, I believe the basic problem is that when your code sets .Select to false (in the Common Controls 6 version), it is not de-selecting the items - is that correct?
Yes this is my problem!!! Do you know any way around this?
Jul 6 '07 #6

Expert 5K+
P: 8,434
Yes this is my problem!!! Do you know any way around this?
I'm just having a look at it now. One problem I encountered when I copied your code is that you are not allowed to spell colour correctly in VB. The property name is "ForeColor", spelled the U.S. way.

I doubt this is the issue, as it was probably just put on TheScripts that way, not in your code.
Jul 9 '07 #7

Expert 5K+
P: 8,434
Ok, I have a possible solution. It depends on how accurately you copied your code to your message here on TheScripts. If it is accurate, you should be able to resolve the problem by turning on the "require explicit variable declaration" option (Under Tools | Options | Editor tab). This will keep you from using non-existent variables (such as index). Also, I recommend you get rid of Common Controls version 5, and use version 6 only, to avoid confusion.

Another thing - make sure you're working with the correct listview control. In the posted code, some refers to Listview1, some to Listview3.
Jul 9 '07 #8

P: 36
Hi

Sorry I posted some code and some I had in my mind ( I was at home) So I didnt have access to the code...

But the problem is not misspelling at all. It is just that in the listview in comon control 5 you are not allowed to set a items forecolor. Only the whole listviews forecolor...
This was added in the common control 6....
But here there are a bug with multiselect as you describe
Jul 11 '07 #9

Expert 5K+
P: 8,434
If there is a bug in the multi-select functionality, I don't know what we can do about it.
Jul 12 '07 #10

hariharanmca
100+
P: 1,977
Hi
I have enabled multiselect in my listview. My problem is that when I click inside the listview but not on a item
Expand|Select|Wrap|Line Numbers
  1. .
  2. Set oListItem = ListView3.HitTest(X, y)
  3. oListItem is nothing. This is ok. So i set all the selected property in the listview 
  4.  
to false
Expand|Select|Wrap|Line Numbers
  1. dim i as integer
  2. for i=1 to ListView1.ListItems.Count
  3. ListView1.ListItems.item(index).Selected = False
  4. next
  5.  
My problem is the following
lets say I have 10 items in my list. I click on the first item
then i click below all 10 items select the 3 last items (my clicking and dragging the mouse)
What happends now is that the last 3 is selected but also the first item.
how can I avoid this?
I only want the last 3 to be selected

help is appreciated

I suggest you to use check box in list view. that'll be easy na....
Jul 12 '07 #11

P: 36
I suggest you to use check box in list view. that'll be easy na....
wont work. i want a drag and drop feature like winamp :)
Jul 18 '07 #12

P: 2
I'm having a similar issue where I have two listboxes where I need to be able to drag/drop multiple selections from one to the other. I am not able to multiselect like you're supposed to with the Ctrl &/or Shift keys. It lets you select multiple items (without using the Ctrl &/or Shift keys) just by clicking on the items but you cannot deselect any. This causes the first item to always be selected.
Dec 18 '07 #13

Expert 5K+
P: 8,434
I'm having a similar issue where I have two listboxes where I need to be able to drag/drop multiple selections from one to the other. I am not able to multiselect like you're supposed to with the Ctrl &/or Shift keys. It lets you select multiple items (without using the Ctrl &/or Shift keys) just by clicking on the items but you cannot deselect any. This causes the first item to always be selected.
I'm a bit unclear on what the problem is. Are you asking for help with the listbox that isn't handling multi-select properly, or what?
Dec 19 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.