Using new to create an instance of an object

rkeslar75

Member
Joined
Oct 11, 2007
Messages
5
Programming Experience
5-10
I have a checkbox that when clicked is supposed to highlight all entries in a listbox, but i keep getting an error that says to use the New keyword when creating an instance of an object, but I can't figure out where to use it. this is the sub:

Private Sub chkSelectAll1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSelectAll1.CheckedChanged

Dim i As New Integer
If chkSelectAll1.Checked Then
For i = 0 To Me.lstFileList.Items.Count - 1
Me.lstFileList.SelectedItem(i) = True
Next i
End If
End Sub

Can you see what might be wrong here?
Thanks
(vb.net 2005 winform)
 
hmm...getting somewhere

I found out that I have to use the SetSelected Method, but for some reason it only highlights the second entry in my list instead of all of them

Dim i As New Integer
If chkSelectAll1.Checked Then
For i = 0 To Me.lstFileList.Items.Count - 1
Me.lstFileList.SetSelected(1, True)

Next i

Any idea why?
 
ahh i see

Gotta use

Me.lstFileList.SetSelected(i, True)

instead of Me.lstFileList.SetSelected(1, True)

Since the first value reprsents the item in the zerobased index

so 1 would be the second item. I wanted all so I need to use i.
 
Back
Top