有个listview 窗口显示了如下信息             序号    姓名     学号   性别    专业
              1     张三     2011    女   计算机
              2     张华     1586    女   法学
              3     林林     5203    男   动物学
              4     李胡     5466    女   会计
              5     赵珊     5866    女   考古学
    text1 , text2, text3 要求:想过通过鼠标双击listview内的“任意”一个内容,在text中显示相关内容。 比如“任意”双击“动物学” , 要求达到如下效果:
  1、双击“动物学”, 在text1 中显示双击获得的内容  “动物学” 
  2、双击“动物学”, 在text2 中显示 动物学 的列表头信息 “专业”
  3、双击“动物学”, 在text3 中显示 动物学 的列表信息行数 “3”请高手帮忙协助解决,在书上查找了很多关于listview的详细使用,但是就是无法自行解决。谢谢 
 

解决方案 »

  1.   

    Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Private Type POINTAPI
        X As Long
        y As Long
    End TypePrivate Type LVHITTESTINFO
       pt As POINTAPI
       flags As Long
       iItem As Long
       iSubItem As Long
    End TypePrivate Const LVM_FIRST = &H1000
    Private Const LVM_SUBITEMHITTEST = (LVM_FIRST + 57)Private Sub ListView1_Click()
        Dim tem$
        Dim lvhti As LVHITTESTINFO
        Dim SelectRow As Integer, SelectCol As Integer
        Call GetCursorPos(lvhti.pt)
        Call ScreenToClient(ListView1.hwnd, lvhti.pt)
        Call SendMessage(ListView1.hwnd, LVM_SUBITEMHITTEST, 0, lvhti.pt)
        SelectRow = lvhti.iItem + 1
        SelectCol = lvhti.iSubItem
        If SelectRow < 1 Then
        Else
            If SelectCol = 0 Then
            Else
                Debug.Print ListView1.ListItems(SelectRow).ListSubItems(SelectCol).Text '单元格内容
                Debug.Print SelectRow                                                   '行数
                Debug.Print ListView1.ColumnHeaders.Item(SelectCol + 1).Text            '列名
            End If
        End If
    End Sub
      

  2.   

    listview排序怎么搞?一直每弄懂
      

  3.   

    vbload  你好,我还是不会呢。有简单的代码吗》 
      

  4.   

    listview有行列属性  直接读取就行了..排序也有相应的属性 并不复杂 只是默认排序好像是以文本形式排列的  要对数字排序还得用API