List view control in VB.NET

anandasa

Newcomer
Joined
May 9, 2003
Messages
3
Hi

Can any one tell us the way to retrieve the row number in the list view control through a VB.NET application?

Thank you

Regards
Ananda Saravanan A
 
Visual Basic:
ListView1.SelectedItems(0).Index()

That will give the index of the row within the listview

Andy
 
Hi Andy

Iam getting error like,

'An Unhandled exception of type 'System. ArgumentOutOfRangeException' occurred in system.windows.forms.dll. Additional information: Specified argument was out of the range of valid values'
when I used your syntax.

Even though I had two rows with value in the list view.

Regards
Anand
 
I'm guessing you have no selected row so trying to reference row 0 isn't valid. You'll have to check to the number of selected rows bofore using that code.

-Nerseus
 
You can use the following code to select the last item enterd.

Code:
'does the listcontain items??
If Me.ListBox1.Items.Count() > 0 Then
   'If no selection, choose last list item.
   If Me.ListBox1.SelectedIndex = -1 Then
      Me.ListBox1.SelectedIndex = Me.ListBox1.Items.Count() - 1
   End If
End If

regards hilmar
 
Last edited:
Back
Top