如何获得listview选择栏和&更新它&反映它对数据库的变化

时间:2011-11-25 11:55:50

标签: vb.net visual-studio-2008 listview ms-access-2003

我正在使用ms访问在vb.net中进行项目 我使用listview来显示表中的数据 我想显示不同列的不同上下文菜单条 我使用硬逻辑来完成它以获得列号如下:

 Private Function getClickedColumn(ByVal pListView As ListView, ByVal pMouseX As Integer) As Integer
    Dim result As Integer = 0

    'Get column rights
    Dim colRights As New List(Of Integer)
    Dim colWidths As New List(Of Integer)
    For Each col As ColumnHeader In pListView.Columns
        colWidths.Add(col.Width)
        Dim colRight As Integer = 0 ' - pListView.Columns.Item(0).Width 'Subtract this if you were collecting lefts instead of rights
        For i As Integer = 0 To colWidths.Count - 1
            colRight += colWidths(i)
        Next
        colRights.Add(colRight)
    Next

    'Which column does the mouse X fall inside?
    Dim colIndex As Integer = 0
    For Each colRight As Integer In colRights
        If pMouseX <= colRight Then
            result = colIndex
            Exit For
        End If
        colIndex += 1
    Next

    Return result
End Function

我也想编辑listview&amp;的任何单元格。将其结果更新到数据库。 我该怎么做?

1 个答案:

答案 0 :(得分:0)

为什么不使用DataGrid,这将允许编辑,值检查,知道列,...