Results 1 to 9 of 9

Thread: How to set a number of selections in a listview

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    How to set a number of selections in a listview

    Hello, my friends. Here again asking for your help.

    I have a combobox, where a user choosses a number. Then, that user will select rows from a listview up to that number. I just do not know how make listview accepts no more selections.

    As always, any help will be highly appreciated

    Nelson

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How to set a number of selections in a listview

    Should be easy right? When you've got enough selections disable further selections! Is it heck as like. No tracking of the last selection made anywhere within the control! I've tried everything I can think of and had to settle for this rather inadequate procedure ...

    vb.net Code:
    1. Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    2. 'Now you'd think that .SelectedIndex at this point might be the last selected item.
    3. 'It isn't. It's the lowest selected index. Useless!!!!
    4.  
    5.         If ListBox1.SelectedItems.Count > Limit Then
    6.             ListBox1.ClearSelected()
    7.             MsgBox("Sorry. Selection limit exceeded. Please try again!")
    8.         End If
    9.  
    10.     End Sub
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: How to set a number of selections in a listview

    Hello dunfiddlin,

    Once again I thank your time and help. On tye other hand, sorry I did not answer earlier, I at the office.

    I am working with a listview control, not with a listbox. It did not work, listview has no .ClearSelected property.

    If you get another idea, please let me know.

    Thanks a lot,

    Nelson

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to set a number of selections in a listview

    Every item has a Selected property. Loop through the Items and set the Selected property to True or False, depending on whether the index is less than the number selected by the user.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: How to set a number of selections in a listview

    Hi jmcilhinney,

    Thank you.

    I have read you proposal and tryed some coding. But I still do not manage VB quite well. I could not code that: "loop through the Items". I do not mean to abuse, but if you give some clues, maybe I will.

    Thank you

    Nelson

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to set a number of selections in a listview

    There are plenty of clues in my previous post. You should already be familiar with the Items property of the ListView, which is a collection of all the items. I said to use a loop and use the index of each item so a For loop is the only logical choice. Use a For loop to access each item in a list is one of the more fundamental things you can do in VB.NET and is tackled quite early on by an decent beginners tutorial so, if you don't know how to do it, I suggest that you take some time to go through a decent beginners tutorial from start to finish before proceeding with this project. Here's one now:

    http://www.homeandlearn.co.uk/net/vbnet.html

    For loops are addressed in chapter 4.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: How to set a number of selections in a listview

    Thank you, jmcilhinney.

    I will try to be a decent beginner.

    Nelson

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

    Re: How to set a number of selections in a listview

    Quote Originally Posted by necalabria View Post
    I will try to be a decent beginner.
    That was a decent tutorial for beginners rather than a tutorial for decent beginners.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: How to set a number of selections in a listview

    A decent tutorial for beginners needs a decent beginner.

    I will work on that.

    Thank you.

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