如题!
谢谢!

解决方案 »

  1.   

    treview有一个node_click()事件,你可以捕捉node.text来用户点击的node项
      

  2.   

    楼上的老兄,我问的可是listview呀
      

  3.   

    如果不容易解决的话,建议用grid控件。
      

  4.   

    笨方法倒是有
    Private Sub lvw1_Mouseup(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim i As Integer
        If Button = 2 Then
            For i = 1 To lvw1.ColumnHeaders.Count
                If x >= lvw1.ColumnHeaders(i).Left And x < lvw1.ColumnHeaders(i).Left + lvw1.ColumnHeaders(i).Width Then
                    If i = 1 Then
                        MsgBox (lvw1.ListItems(lvw1.SelectedItem.Index).Text)
                    Else
                        MsgBox (lvw1.ListItems(lvw1.SelectedItem.Index).SubItems(i - 1))
                    End If
                End If
            Next
        End If
    End Sub
    只是想求更高效,更正规的方法
    先放几天看看吧,过几天再结贴。
      

  5.   

    下面这个方法返回在ListView中x,y位置上的ListItem对象,找到鼠标点击的坐标,然后检查HitTest(x,y)是不是为Nothing,如果不是则是ListView的ListItem对象
    ListView1.HitTest(x, y)
      

  6.   

    我建议你用datagrid,改一改外观,效果也不差
      

  7.   

    dim i as integerPrivate Sub listview1_ItemClick(ByVal Item As MSComctlLib.ListItem)
        i = Item.Index
    End SubPrivate Sub listview1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Button = 2 Then
            MsgBox i
        End If
    End Sub
      

  8.   

    to lxcc(虫莲) 
    你给出的方法还是取得的行值呀
      

  9.   

    Private Sub ListView1_Click()
        If ListView1.ListItems.Count = 0 Then Exit Sub
        MsgBox ListView1.SelectedItem.Text
    End Sub
      

  10.   

    Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        If ListView1.ListItems.Count = 0 Then Exit Sub
        If Button = 2 Then
            MsgBox ListView1.SelectedItem.Text
        End If
    End Sub
      

  11.   

    HOWTO: Find Out Which Listview Column Was Right-Clicked
    The information in this article applies to:
    Microsoft Win32 Software Development Kit (SDK)This article was previously published under Q125694 
    SUMMARY
    You can use the technique described in this article to find out which column was clicked after right-clicking the listview column header. 
    MORE INFORMATION
    LVN_COLUMNCLICK notifies a listview's parent window when a column is clicked using the left mouse button, but no such notification occurs when a column is clicked with the right mouse button. Windows 95 sends an NM_RCLICK notification to the listview's parent window when a column is clicked with the right mouse button, but the message sent does not contain any information as to which column was clicked, especially if the window is sized so that the listview is scrolled to the right. The correct way to determine which column was clicked with the right mouse button, regardless of whether the listview is scrolled, is to send the header control an HDM_HITTEST message, which returns the index of the column that was clicked in the iItem member of the HD_HITTESTINFO struct. In sending this message, make sure the point passed in the HD_HITTESTINFO structure is relative to the header control's client coordinates. Do not pass it a point relative to the listview's client coordinates; if you do, it will return an incorrect column index value. The header control in this case turns out to be a child of the listview control of LVS_REPORT style. The following code demonstrates this method. Note that while the code processes the NM_RCLICK notification on a WM_NOTIFY message, you also process the WM_CONTEXTMENU message, which is also received as a notification when the user clicks the right mouse button. 
    Sample Code
       case WM_NOTIFY:
       {
           if ((((LPNMHDR)lparam)->code == NM_RCLICK))
           {
              HWND hChildWnd;
              POINT pointScreen, pointLVClient, pointHeader;
              DWORD dwpos;          dwPos = GetMessagePos();          pointScreen.x = LOWORD (dwPos);
              pointScreen.y = HIWORD (dwPos);          pointLVClient = pointScreen;          // Convert the point from screen to client coordinates,
              // relative to the listview
              ScreenToClient (ghwndLV, &pointLVClient);          // Because the header turns out to be a child of the
              // listview control, we obtain its handle here.
              hChildWnd = ChildWindowFromPoint (ghwndLV, pointLVClient);          // NULL hChildWnd means R-CLICKED outside the listview.
              // hChildWnd == ghwndLV means listview got clicked: NOT the
              // header.
              if ((hChildWnd) && (hChildWnd != ghwndLV))
              {
                 char szClass [50];             // Verify that this window handle is indeed the header
                 // control's by checking its classname.
                 GetClassName (hChildWnd, szClass, 50);
                 if (!lstrcmp (szClass, "SysHeader32"))
                 {
                    HD_HITTESTINFO hdhti;
               char szBuffer [80];                // Transform to client coordinates
                    // relative to HEADER control, NOT the listview!
                    // Otherwise, incorrect column number is returned.                pointHeader = pointScreen;
                    ScreenToClient (hChildWnd, &pointHeader);                hdhti.pt = pointHeader;
                    SendMessage (hChildWnd,
                                 HDM_HITTEST,
                                 (WPARAM)0,
                                 (LPARAM) (HD_HITTESTINFO FAR *)&hdhti);
                   wsprintf (szBuffer, "Column %d got clicked.\r\n",
                             hdhti.iItem);               MessageBox (NULL, szBuffer, "Test", MB_OK);
                 }
              }
           }
           return 0L;
       }
      

  12.   

    楼上的大侠,怎么把这段代码用到VB里去呢?(我E文不好)
      

  13.   

    请rappercn(rapper)兄把上述C代码用VB写一个吧。
      

  14.   

    Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Button = 2 Then
            Dim i As Integer
            Dim LngWidth As Long
            LngWidth = 0
            For i = 1 To ListView1.ColumnHeaders.Count
                LngWidth = LngWidth + ListView1.ColumnHeaders(i).Width
                If x <= LngWidth Then MsgBox i: Exit Sub
            Next i
        End If
    End Sub
    '想来想去,这是最简单的方法。
      

  15.   

    http://www.mvps.org/vbnet/index.html?code/subclass/lvheadernotifications.htm给你找了一篇VB的,这里放不下,我也实在是没兴趣没时间翻译,你自己看看吧。
      

  16.   

    谢谢各位了,我的另外一个贴子上已经有了答案了。
    有兴趣可以看看
    http://expert.csdn.net/Expert/topic/1897/1897586.xml?temp=.9763758
    结贴