Selecting in Listview

ninjaimp

Well-known member
Joined
Jun 13, 2007
Messages
80
Programming Experience
1-3
Hi

i have a listview which is populated with a number of 'Appointments' and when selected this fills a number of lables with information.

now on the first click it works fine and everything gets populated but when a different row is selected i get an error.

the code im using is

VB.NET:
Dim selection As ListViewItem = lstDays.GetItemAt(e.X, e.Y)


        If (selection IsNot Nothing) Then
            lblCustID.Text = selection.SubItems(2).Text
            FillCustData(selection.SubItems(2).Text)
        Else
            MsgBox("There is no current appointment set for " & selection.SubItems(2).Text & " Would you like to make one?")
            Return
        End If
Dim selection As ListViewItem = lstDays.GetItemAt(e.X, e.Y)

the error is appearing on the row 'lblCustID.Text = selection.SubItems(2).Text '
with the error message
' InvalidArgument=Value of '2' is not valid for 'index'. Parameter name: index '

i wondered if anyone could help
 
Think i should expand as it could be clearer than above.

I have a listview which is loaded on form load and given a number of rows (time slots)

Then a second procedure checks a db and if any of the records match one of the time slots in the listview, then additional info is added into column 2 next to the matching time slot.

now the idea is when a row s clicked that contains dat in both columns then this fills a number of labels with data based on the value of the selected record.

My problem lies when a row is selected that does not contain a 'matched record' hence, column 2 of the listview has no data and hence is throeing a wobbly.

How can i check to see if column 2 of a listview is empty or null?

many thanks
 

Latest posts

Back
Top