[英]My Edit Button and Delete Button are conficting
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在我对 select 列表视图和编辑按钮进行编码后,我尝试使用 VB.net 在列表视图中编辑我的记录,但在我对删除按钮进行编码后,它开始出错
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这是我的列表视图 Select 代码
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
ArgumentOutofRangeException 未处理
when I remove my listview select code both buttons work fine tho当我删除列表视图 select 代码时,两个按钮都可以正常工作
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.删除选定的 ListView 项目获取选定项目的索引然后使用该索引来标识要删除的项目。
Private Sub RemoveListViewItem()
Dim myIndex As Integer = CustomerList.SelectedIndices(0)
CustomerList.Items(myIndex).Remove()
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.