Hi,
I have a button which loads a table from an MSACCESS file into a listview. Here is my code:
CODE
Private Function LoadDataBaseToListview()
imgIcons.Images.Add("account", My.Resources.user) 'Add user icon to imagelist
' Load the data.
' Open the database.
Dim conn As OleDbConnection = GetDbConnection()
' Select records.
Dim cmd As New OleDbCommand("SELECT * FROM Accounts", conn) 'Select the Accounts table
Dim data_reader As OleDbDataReader = cmd.ExecuteReader()
Do While data_reader.Read()
Dim account As New ListViewItem(data_reader.Item("UserID").ToString) 'Sets the username
account.SubItems.Add(data_reader.Item("PassID").ToString) 'Sets the password
lstAccounts.Items.Add(account)
Me.lstAccounts.Items.Item(lstAccounts.Items.Count - 1).ImageKey = "account" 'Adds the image key "account" to the item "Username"
Loop
' Close the connection.
conn.Close()
End Function
When the button is clicked, it runs this function, populating the table into the listview. Now, I would like to add the function where a user can delete rows by right-clicking a row in the listview and selecting delete. I have added a context-menu, and I can delete listview items, however I don't know how to delete the row in the MSACCESS database. Any ideas? Thanks
CODE
'To delete a listview entry
For i As Integer = lstAccounts.Items.Count - 1 To 0 Step -1
If lstAccounts.Items(i).Selected Then lstAccounts.Items.RemoveAt(i)
Next