Reputation: 136
I wrote piece of cod for add item right after selected item in listview:
Private Sub InsertBeforeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InsertBeforeToolStripMenuItem.Click
ListView1.Items.Add(Me.ListView1.Items(ListView1.SelectedIndices(0) + 1).Clone)
For i = 0 To ListView1.Items.Count - 1
ListView1.Items(i).Text = i + 1.ToString
Next
end sub
but its not work this cod add item to end of listview instead of after selected item The question is how can i achive that purpose? thank you all.
Upvotes: 1
Views: 262
Reputation: 74605
How about:
If(ListView1.SelectedIndices.Count > 0) Then
ListView1.Items.Insert(ListView1.SelectedIndices(0) + 1, "new item")
Else
ListView1.Items.Add("new item")
End If
Upvotes: 1