It looks like the original poster was naughty and got himself banned. Anyway here is a solution for anyone else who needs it.
Setup
•Create new project called EditListviewExample in Visual basic 2008
•Add listview called lvMain
•Add Item1, Item2, Item3, Item4, and Item5 as Items using the design view
•Change View to list
•Add a button named btnGet, numericupdown named nudGet, and a textbox named txtGet
•Add a button named btnPut, numericupdown named nudPut, and a textbox named txtPut
•Add Option Strict On and Option Explicit On to the code
CODE
Option Strict On
Option Explicit On
Public Class frmMain
Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
'This is to check and see if the index provided by nudGet is a valid index, otherwise
'and exception will be thrown.
If CInt(nudGet.Value) < lvMain.Items.Count Then
'the values of a listview is held in the .items property
txtGet.Text = lvMain.Items(CInt(nudGet.Value)).Text
Else
MessageBox.Show("Selection falls outside of the bounds of the listview")
End If
End Sub
Private Sub btnPut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPut.Click
'This is to check and see if the index provided by nudPut is a valid index, otherwise
'and exception will be thrown.
If CInt(nudPut.Value) < lvMain.Items.Count Then
lvMain.Items(CInt(nudPut.Value)).Text = txtPut.Text
Else
MessageBox.Show("Selection falls outside of the bounds of the listview")
End If
End Sub
End Class
The way to access any value within a listview is to access the item() property of the listview. This example will get the item value specified by the numericupdown or conversely put a value in the select item. You must realize that a listview is zero based like most other .NET controls and structures. If you get the value from the first slot you should ask for item(0).
The listview is an incredible powerful control and you can do some very amazing things with it. You can also get the highlighted item by using selecteditems() or get the item under the mouse by using getimageat().
Comment/Reply (w/o sign-up)