I want to delete an item from list view and at the same I want delete the item from the Releavant table when I click the okay button in the ** search form** i want to delete the item from listview and as well as to update it to Sell table
listview is in the** form7**
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Productid As String = ComboBox2.Text
myCommand = New SqlCommand(" DELETE FROM [Sells] WHERE P_Id = ' " & ComboBox2.Text & "' AND Bill_No='" & Val(TextBox1.Text) & "'", myConnection)
Public Sub listview()
If Form7.ListView1.Items.Count = 0 Then
MsgBox("No Data to Delete", MsgBoxStyle.Information)
Dim intindex As Integer
For Each lstdata As ListViewItem In Form7.ListView1.SelectedItems
intindex = lstdata.Index
Catch err As Exception
Catch err As Exception
in here the data won't neither delete from listview nor from table though i get the message No Data to Delete and Update successfully this the coding in the remove item in the form7
Dim intResponse As Integer
intResponse = MsgBox("Please Select the Product Id", MsgBoxStyle.OkCancel)
If intResponse = vbOK Then
varibles.billno = Val(TextBox14.Text)
' code to end the app, such as "Me.Close" would go here
What I like to do when using listviews, is to load the table's identity column into the first column of the listview. (Then make the column width 0 to hide it from the user)
Then to reference it, I use:
Dim myUnique As String 'Your data type here
If IsNothing(ListView1.SelectedItems) = False Then
For Each Itm as ListViewItem in ListView1.SelectedItems
myUnique = Itm.Text
MsgBox("Please select an item first!")
You have just referenced the identity that is stored in the first (hidden or not) column of the row.
You can now use this to manipulate data/the list view.
If you stored the database indentity column in the first column of the list view, but hid the column, the user will only see col1, col2 and col3. So when the user clicks the column " 5|Name|Date|Info " You know that that corresponds to the database entry with an identity of 5.
By using the index of the item ( What you are doing now ) you will try to execute a delete statement on the index of 1 (2nd item in the list) which will produce undesired outcomes.