Multiselect in a listview (VB6)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Proogeren
    New Member
    • May 2007
    • 36

    Multiselect in a listview (VB6)

    Hi
    I have enabled multiselect in my listview. My problem is that when I click inside the listview but not on a item
    Code:
    .
    Set oListItem = ListView3.HitTest(X, y)
    oListItem is nothing. This is ok. So i set all the selected property in the listview
    to false
    Code:
    dim i as integer
    for i=1 to ListView1.ListItems.Count
    ListView1.ListItems.item(index).Selected = False
    next
    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
  • Proogeren
    New Member
    • May 2007
    • 36

    #2
    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
    Code:
    Listview.Listitems.Item(2).forecolour = xxx
    If anyone knows how to solve this plz help

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      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?

      Comment

      • Proogeren
        New Member
        • May 2007
        • 36

        #4
        Originally posted by Killer42
        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... :(

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by Proogeren
          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?

          Comment

          • Proogeren
            New Member
            • May 2007
            • 36

            #6
            Originally posted by Killer42
            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?

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by Proogeren
              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.

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

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

                Comment

                • Proogeren
                  New Member
                  • May 2007
                  • 36

                  #9
                  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

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    If there is a bug in the multi-select functionality, I don't know what we can do about it.

                    Comment

                    • hariharanmca
                      Top Contributor
                      • Dec 2006
                      • 1977

                      #11
                      Originally posted by Proogeren
                      Hi
                      I have enabled multiselect in my listview. My problem is that when I click inside the listview but not on a item
                      Code:
                      .
                      Set oListItem = ListView3.HitTest(X, y)
                      oListItem is nothing. This is ok. So i set all the selected property in the listview
                      to false
                      Code:
                      dim i as integer
                      for i=1 to ListView1.ListItems.Count
                      ListView1.ListItems.item(index).Selected = False
                      next
                      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....

                      Comment

                      • Proogeren
                        New Member
                        • May 2007
                        • 36

                        #12
                        Originally posted by hariharanmca
                        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 :)

                        Comment

                        • BeckyBair
                          New Member
                          • Dec 2007
                          • 2

                          #13
                          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.
                          Last edited by Killer42; Dec 19 '07, 12:37 AM.

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #14
                            Originally posted by BeckyBair
                            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?

                            Comment

                            Working...