• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Short VB .Net question, please help!

JonTheBaller

Golden Member
In VB .Net, I made a ListView object with two columns of data (let's say item & price). How do I update a specific index in the ListView? For example, what would my code look like if I wanted to update the price of the 2nd listing in ListView1? Thanks.
 
I could've told you the answer if you asked me 6 months ago. I'll just bump for ya since I am now a complete dummy in .NET.
 
Not the best example mind you....but it works....lots of other tests need to be added, but I just coded it up for you quickly:

Add One listview (two columns), two text boxes, one command button and paste this code Leave the names default:

What you're looking for is the listview.selecteditemindices which returns a System.Windows.Forms.ListView.SelectedIndexCollection

[edit] damn vb.net ide [/edit]

Add Two Class Vars:
'class variable for storing list view's current selected item index
Dim myListIndex As System.Windows.Forms.ListView.SelectedIndexCollection
'class vairable for storing list view's current selected item
Dim itmx As System.Windows.Forms.ListViewItem


Add the following to the form_load event:
Dim myx As System.Windows.Forms.ListViewItem
Dim i As Integer = 0
Dim j As Integer = 10
For i = 0 To j
myx = Me.ListView1.Items.Add("Decription # " & i)
myx.SubItems.Add("Price = $" & i * 2 & ".00")

Next
'change button's format
Me.Button1.Text = "Update The Stuff"
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""

add the following to the listview1_click event

'get the selected indexes from the listview
myListIndex = Me.ListView1.SelectedIndices
'single select list box.....all we care is the count of selected items is > 1
If myListIndex.Count > 0 Then
'get the first one in the global listindex var
itmx = Me.ListView1.Items(myListIndex(0))
'set the text boxes to the current values of the selected item
Me.TextBox1.Text = itmx.SubItems(0).Text
Me.TextBox2.Text = itmx.SubItems(1).Text
End If

add the following to the button1_click event
If (Me.TextBox1.Text <> vbNullString) And (Me.TextBox2.Text <> vbNullString) Then
If Not itmx Is Nothing Then
itmx.SubItems(0).Text = Me.TextBox1.Text
itmx.SubItems(1).Text = Me.TextBox2.Text
End If
End If



 
Back
Top