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
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:
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
'Now you'd think that .SelectedIndex at this point might be the last selected item.
'It isn't. It's the lowest selected index. Useless!!!!
If ListBox1.SelectedItems.Count > Limit Then
ListBox1.ClearSelected()
MsgBox("Sorry. Selection limit exceeded. Please try again!")
End If
End Sub
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
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.
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
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.
Re: How to set a number of selections in a listview
Thank you, jmcilhinney.
I will try to be a decent beginner.
Nelson
Re: How to set a number of selections in a listview
Quote:
Originally Posted by
necalabria
I will try to be a decent beginner.
That was a decent tutorial for beginners rather than a tutorial for decent beginners. :)
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.