开发者

Retrieving data from ListView control in VB.NET

I have a ListView setup in details mode that looks like this:

Retrieving data from ListView control in VB.NET

When the user presses the delete button, I need to go ahead and delete their record from the database. This I can do fine, but I'm stuck on how I retrieve the开发者_如何学C data that is highlighted in the ListView control. I've tried using Google but all the examples I found have failed to work.

Can someone help me out here?


You should be able to get the underlying object by using:

ListView1.SelectedItems(0)

Once you remove it from the database you should rebind the data.


Dim name, room, subject, date, period As String

If listviewName.SelectedItems.Count > 0 then

        '*********** transfer selected data on declare String variable ************'
        name= listviewName.SelectedItems(0).SubItems(0).Text
        room = listviewName.SelectedItems(0).SubItems(1).Text
        subject = listviewName.SelectedItems(0).SubItems(2).Text
        date= listviewName.SelectedItems(0).SubItems(3).Text
        period= listviewName.SelectedItems(0).SubItems(4).Text

        '*********** delete **************'
        cmd1.Connection = MYSQLCON
        MYSQLCON.Open()
        cmd1.CommandText = "DELETE FROM tablename WHERE columnname = '" & name & "'"
        reader = cmd1.ExecuteReader
        MYSQLCON.Close()

End If
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜