I am trying to edit my records in the list view using VB.net after I code my select list view and edit button it works but after I code my delete button it starts to do error
Here's my Edit button
txtID.Text = CustomerList.SelectedItems(0).SubItems(0).Text
txtFN.Text = CustomerList.SelectedItems(0).SubItems(1).Text
txtLN.Text = CustomerList.SelectedItems(0).SubItems(2).Text
txtAdr.Text = CustomerList.SelectedItems(0).SubItems(3).Text
cbOrder.Text = CustomerList.SelectedItems(0).SubItems(4).Text
cbPaymen.Text = CustomerList.SelectedItems(0).SubItems(5).Text
DatePicker.Text = CustomerList.SelectedItems(0).SubItems(6).Text
End Sub
Here's my List view Select code
Dim s = n1 + n2 + n4 + n8
br = ListBox1.SelectedItem.ToString()
CustomerList.SelectedItems(0).SubItems(1).Text = txtFN.Text
CustomerList.SelectedItems(0).SubItems(2).Text = txtLN.Text
CustomerList.SelectedItems(0).SubItems(3).Text = txtAdr.Text
CustomerList.SelectedItems(0).SubItems(4).Text = cbOrder.Text
CustomerList.SelectedItems(0).SubItems(5).Text = cbPaymen.Text
CustomerList.SelectedItems(0).SubItems(6).Text = DatePicker.Text
CustomerList.SelectedItems(0).SubItems(7).Text = i
CustomerList.SelectedItems(0).SubItems(8).Text = br
CustomerList.SelectedItems(0).SubItems(9).Text = s
End Sub
Here's my Delete Button Code
CustomerList.Items.Remove(CustomerList.SelectedItems(0))
and I get an error:
ArgumentOutofRangeException was unhandled
when I remove my listview select code both buttons work fine tho
please help
To remove a selected ListView item get the index of the selected item Then use that index to identify the item to remove.
Private Sub RemoveListViewItem()
Dim myIndex As Integer = CustomerList.SelectedIndices(0)
CustomerList.Items(myIndex).Remove()
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.