Sorry i am a relatively inexperienced programmer requiring urgent help,

I am trying to select an appropriate field in list view then for a second form to appear and the data entered in this form i want to replace by what was previously selected,.

Have got data to add ok just not edit see code below area in colour is area im having dificulty with, thanks for any help in advance


Private Sub bttnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnadd.Click
' this sub takes the informaiton that the user has inputed into frmaddedit and adds it to the list view under its approprate heading in spylist in the form display screen
If Me.Text = "Add" Then
Dim spyinfo As Array

dispscreen.spylist.Items.Add(fstnam.Text)
Dim i As Integer = 0
i = dispscreen.spylist.Items.Count - 1
dispscreen.spylist.Items.Item(i).SubItems.Add(surnam.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(age1.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(cdenam.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(specskil.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(sex.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(distinmar.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(swbank.Text)

Me.Hide()
Else
' this part of the sub takes information that has been inputed into edit screen when the edit button has been clicked and replaces it by what was previously selected
If Me.Text = "Edit" Then
'dispscreen.spylist.Items(dispscreen.spylist.SelectedIndices.Item(0))
Dim i As Integer = 0

i = dispscreen.spylist.Items.Count - 1
dispscreen.spylist.SelectedItems.Item(i).SubItems.Add(fstnam.Text)
dispscreen.spylist.SelectedItems.Item(i).SubItems.add(surnam.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(age1.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(cdenam.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(specskil.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(sex.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(distinmar.Text)
dispscreen.spylist.Items.Item(i).SubItems.Add(swbank.Text)

Me.Hide()
End If
End If

'this part of the sub sets the input screen back to a blank value it basically clears the formadd back to a blank state ready for the next spy to be added
fstnam.Text = ""
surnam.Text = ""
age1.Text = ""
cdenam.Text = ""
specskil.Text = ""
sex.Text = ""
distinmar.Text = ""
swbank.Text = ""
End Sub