Page 1 of 1

Listview help

Posted: Wed Aug 22, 2012 10:36 pm
by muttley1968
Right I have a list view and I am adding info to it with a button like this
Code: Select all
        ListView1.Items.Add("richardjmanning")
        ListView1.Items(0).SubItems.Add(ram.Next(0, ListBox2.Items.Count))
        ListView1.Items(0).SubItems.Add(ram.Next(1, ListBox2.Items.Count))
        ListView1.Items(0).SubItems.Add(ram.Next(2, ListBox2.Items.Count))
        ListView1.Items(0).SubItems.Add(ram.Next(3, ListBox2.Items.Count))
        ListView1.Items(0).SubItems.Add(ram.Next(4, ListBox2.Items.Count))
        ListView1.Items(0).SubItems.Add(ram.Next(5, ListBox2.Items.Count))
        ListView1.Items(0).SubItems.Add(ram.Next(6, ListBox2.Items.Count))
But I want it to add new line every time but it doesnot it add a new richardjmanning but no new random numbers why is this and also is there a way to compare weather a list view contains numbers
soo say I have 7 labels on my form all with different numbers is there any way to see if an item in my listview contains
any of these numbers and display the username "richardjmanning" of the user that has the most numbers

If it helps its for a lotto system the man hits the button to add a user and then when ready to pick a winner hit another button that make the labels go to random number from 1 to 100 and I want to see what 5 users are clostest to the win

Re: Listview help

Posted: Wed Aug 22, 2012 10:54 pm
by comathi
The reason is quite simple. Every time, you're telling it to add a new ListViewItem, but then you're telling it to add the subitems to items(0), so it tries to change the same item every time. This can be solved easily by declaring a ListViewItem and adding the subitems to it before adding it to the control, like so:
Code: Select all
Dim ram As New Random()
        Dim newItem As New ListViewItem
        newItem.Text = "richardjmanning"
        newItem.SubItems.Add(ram.Next(0, ListBox2.Items.Count))
        newItem.SubItems.Add(ram.Next(1, ListBox2.Items.Count))
        newItem.SubItems.Add(ram.Next(2, ListBox2.Items.Count))
        newItem.SubItems.Add(ram.Next(3, ListBox2.Items.Count))
        newItem.SubItems.Add(ram.Next(4, ListBox2.Items.Count))
        newItem.SubItems.Add(ram.Next(5, ListBox2.Items.Count))
        newItem.SubItems.Add(ram.Next(6, ListBox2.Items.Count))

        ListView1.Items.Add(newItem)
Please note: I've re-declared ram As New Random() in the above code just so that I could use it myself and test it. If you've already declared somewhere else where you can access it, you can remove that part from the code I'm giving you ;)

Re: Listview help

Posted: Wed Aug 22, 2012 11:09 pm
by muttley1968
That works AMAZING thank is there a way now were I can display the Top 5 people clostest to hitting the right numbers ill get screen shots and all now to make it easier to understand

Re: Listview help

Posted: Wed Aug 22, 2012 11:12 pm
by muttley1968
Right soo here is the first page the balls will pick random numbers and everything is well just look and see
Image

Then here you add users to the draw now what I want to do is on page 1 there are winners 1 to 5 I want to put the 5 people from this list box with the closest numbers to see who won the money
Image