想把listview删除改成用DataGridView
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim number As Integer
number = ListView1.Items.IndexOf(ListView1.FocusedItem) ''获取选中项的索引号
Dim str As String = ListView1.Items(number).SubItems(3).Text ''记录选中项的第四列(配送人员)的值 Dim querystring As String = "delete * from 配送数据库 where 配送人员 = '" & str & "'"
Dim conn As New OleDb.OleDbConnection(connectionstring)
Try
conn.Open()
Dim cmd As New OleDb.OleDbCommand(querystring, conn)
cmd.ExecuteNonQuery() ''执行删除命令
ListView1.Items(number).Remove() ''删除ListView1中选中的记录 MsgBox("删除选中记录!")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
[解决办法]
这个是DataGridView1的最基本操作了。上网搜索吧。
[解决办法]
参考:winform DataGridView 的18种常见属性
http://www.wotui.net/wotui/news/show.asp?id=2578&pid=125