Vb.net 如何获取listview选定列并更新它并将其更改反映到数据库
我正在用ms access在vb.net中做项目 我使用listview显示表中的数据 我想为不同的列显示不同的上下文菜单条 我使用硬逻辑来获得列号,如下所示:Vb.net 如何获取listview选定列并更新它并将其更改反映到数据库,vb.net,visual-studio-2008,listview,ms-access-2003,Vb.net,Visual Studio 2008,Listview,Ms Access 2003,我正在用ms access在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 colRig
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的任何单元格,并将其结果更新到数据库。
我怎样才能做到这一点呢?为什么不改用DataGrid呢?DataGrid将允许编辑、值检查、了解列