Hi guys,

Currently I am updating a listview with data in it via clicking on the selected row and displaying that row data onto textboxes and then updating it. What the data has is ID number follow name and QTY. What I want to add to this function is to update the quantity of a specific ID without clicking on the specific row in listview but by searching the ID, returning its results in the textbox, update it .

Private Sub ListView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
        If ListView1.Items.Count = 0 Then
            MsgBox("No Item In The List")
            Exit Sub
        End If
        slist = ListView1.SelectedItems(0)
        txtItemName.Text = slist.SubItems(1).Text
        txtQty.Text = slist.SubItems(2).Text
       
    End Sub

Hi guys,

Currently I am updating a listview with data in it via clicking on the selected row and displaying that row data onto textboxes and then updating it. What the data has is ID number follow name and QTY. What I want to add to this function is to update the quantity of a specific ID without clicking on the specific row in listview but by searching the ID, returning its results in the textbox, update it .

I guess your best choice is to find ID using the ListView1.Items.Find(Key) but that depends on how you are populating the Listview. or Loop through the listview and search for text inside specific column.

How you are populating the listview?

i am populating my listview via connecting to my access database using a sql query and then adding it to listview

heres the code

Dim Total As Decimal
Dim lSingleItem As ListViewItem 'The variable will hold the ListItem information so that you can add values to the column you want to change
Dim li As ListViewItem
Dim lngRunningTotal As Decimal
Dim item As String = ""

With Me.ListView1
'.Items.Clear()
.Sorting = SortOrder.Ascending
lSingleItem = ListView1.Items.Add(txtItemNo.Text.Trim) 'Create a new line, and assign the ListItem into the variable so we can add sub items
lSingleItem.SubItems.Add(txtItemName.Text.Trim) 'The first sub item for the first line
lSingleItem.SubItems.Add(txtUnitPrice.Text) 'The second sub item for the first line
lSingleItem.SubItems.Add(txtQty.Text.Trim)
lSingleItem.SubItems.Add(txtUnitTotal.Text)
lSingleItem.SubItems.Add(txtDescription.Text)
End With

heres the code

Dim Total As Decimal
Dim lSingleItem As ListViewItem 'The variable will hold the ListItem information so that you can add values to the column you want to change
Dim li As ListViewItem
Dim lngRunningTotal As Decimal
Dim item As String = ""

With Me.ListView1
'.Items.Clear()
.Sorting = SortOrder.Ascending
lSingleItem = ListView1.Items.Add(txtItemNo.Text.Trim) 'Create a new line, and assign the ListItem into the variable so we can add sub items
lSingleItem.SubItems.Add(txtItemName.Text.Trim) 'The first sub item for the first line
lSingleItem.Name = txtItemName.Text.Trim ' this will act as a Key
lSingleItem.SubItems.Add(txtUnitPrice.Text) 'The second sub item for the first line
lSingleItem.SubItems.Add(txtQty.Text.Trim)
lSingleItem.SubItems.Add(txtUnitTotal.Text)
lSingleItem.SubItems.Add(txtDescription.Text)
End With

Add this to the end of the code

Replace the 1000 inside the Find with the ID you are searching for

Dim FindlvItem() As ListViewItem
FindlvItem = Me.ListView1.Items.Find("1000", False)
FindlvItem(0).SubItems(3).Text = 9999

hth

Edited 3 Years Ago by mike_2000_17: Fixed formatting

index was outside the bounds of array error ?

That mean FindlvItem did not find that you are searching for.

Remember that you are searching for ItemName, if you want to search for ItemNo you had to change thelSingleItem.Name = txtItemName.Text.Trim to move it up so will be after this line lSingleItem = ListView1.Items.Add(txtItemNo.Text.Trim)

With Me.ListView1
'.Items.Clear()
.Sorting = SortOrder.Ascending
lSingleItem = ListView1.Items.Add(txtItemNo.Text.Trim) 'Create a new line, and assign the ListItem into the variable so we can add sub items
 lSingleItem.Name =txtItemNo.Text.Trim ' this will act as a Key 
lSingleItem.SubItems.Add(txtItemName.Text.Trim) 'The first sub item for the first line

lSingleItem.SubItems.Add(txtUnitPrice.Text) 'The second sub item for the first line
lSingleItem.SubItems.Add(txtQty.Text.Trim)
lSingleItem.SubItems.Add(txtUnitTotal.Text)
lSingleItem.SubItems.Add(txtDescription.Text)
End With
This article has been dead for over six months. Start a new discussion instead.