Results 1 to 10 of 10

Thread: all selected items unchecked when unchecking other items in listview

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2014
    Posts
    44

    all selected items unchecked when unchecking other items in listview

    Hi guys...

    Code:
    For Each i As ListViewItem In Me.lvSent.Items
    
                If i.Checked = True Then
                    i.Selected = True
                Else
                    i.Selected = False
    
                End If
            Next
    Using that code I can select items in my listview but when I unchecked one selected item, It unchecked all selected items.

    thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: all selected items unchecked when unchecking other items in listview

    I don't see anything in that code that is going to check or uncheck any items. That code is going to select all checked items and unselect all unchecked items. If you're seeing items get unchecked then that must be happening elsewhere.

  3. #3
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: all selected items unchecked when unchecking other items in listview

    wrong question please delete

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: all selected items unchecked when unchecking other items in listview

    Quote Originally Posted by chrisTemper View Post
    I can select items in my listview but when I unchecked one selected item, It unchecked all selected items.
    Isn't that the way the control is supposed to work, otherwise how could the end user check or uncheck multiple items at the same time?

    So I think you'll need to deselect the items first, then you can check/uncheck one item only, at least that is the way it works as an end user, I didn't actually try any code.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: all selected items unchecked when unchecking other items in listview

    Quote Originally Posted by Edgemeal View Post
    Isn't that the way the control is supposed to work, otherwise how could the end user check or uncheck multiple items at the same time?

    So I think you'll need to deselect the items first, then you can check/uncheck one item only, at least that is the way it works as an end user, I didn't actually try any code.
    Hmmm... I wasn't aware of that. I just tested with a new project and no code and it does indeed behave that way.

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2014
    Posts
    44

    Re: all selected items unchecked when unchecking other items in listview

    Quote Originally Posted by Edgemeal View Post
    Isn't that the way the control is supposed to work, otherwise how could the end user check or uncheck multiple items at the same time?

    So I think you'll need to deselect the items first, then you can check/uncheck one item only, at least that is the way it works as an end user, I didn't actually try any code.
    yes sir... sorry I forgot to ask... how can I unchecked selected Items without automatically unchecking other items too?... That code works fine for me by selecting only... thank you sir...

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2014
    Posts
    44

    Re: all selected items unchecked when unchecking other items in listview

    Quote Originally Posted by jmcilhinney View Post
    That code is going to select all checked items and unselect all unchecked items.
    Yes sir... It is only working in cheking multiple items.. but when I unchecked one checkbox all items were unselected. What I want is even if I unchecked other items. other items will still remains checked

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: all selected items unchecked when unchecking other items in listview

    Quote Originally Posted by chrisTemper View Post
    Yes sir... It is only working in cheking multiple items.. but when I unchecked one checkbox all items were unselected. What I want is even if I unchecked other items. other items will still remains checked
    As has already been said, that's how a ListView works. If you don;t want to uncheck multiple items then don't select multiple items. If you're really determined to make it appear to the user that it doesn't work that way when you uncheck an item in code then you could first add all the selected items to a list of your own, unselect them all, uncheck your item and then reselect the items in your list.

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2014
    Posts
    44

    Re: all selected items unchecked when unchecking other items in listview

    Quote Originally Posted by jmcilhinney View Post
    As has already been said, that's how a ListView works. If you don;t want to uncheck multiple items then don't select multiple items. If you're really determined to make it appear to the user that it doesn't work that way when you uncheck an item in code then you could first add all the selected items to a list of your own, unselect them all, uncheck your item and then reselect the items in your list.
    okay sir thanks... so it is not possible for a listview to do multiple uncheck.... But is it possible in datagridview?...

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: all selected items unchecked when unchecking other items in listview

    Quote Originally Posted by chrisTemper View Post
    okay sir thanks... so it is not possible for a listview to do multiple uncheck.... But is it possible in datagridview?...
    Unchecking a cell in a DataGridView will have no implicit effect on any other rows.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width