No announcement yet.

ListView Notifications - Get Row/Col

  • Filter
  • Time
  • Show
Clear All
new posts

  • ListView Notifications - Get Row/Col

    In the DDT world, I use this next line of code all the time, including within the dialog CallBack function, under various ListView notifications. It's easy enough to use.

    ListView Get Select hDlg, %IDC_ListView to iRow
    I also use these SDK code examples sometimes. But I don't have a complete listing of ListView notifications from which row/col can be extracted, nor the extraction code. These 5 notifications cover most of my needs but I wondered if anyone has documented how to get row/col for all ListView notifications from which row/col can be extracted? I'm not sure what all ListView notifications that involves.

       Local pLVDI As LV_DISPINFOW Ptr
       Local LVNT As NMItemActivate Ptr
       Local LVData As NM_ListView
       Local pNMLV As NMLISTVIEW Ptr
       Case %LVN_GetDispInfo
          pLVDI = Cb.LParam
          iRow = @pLVDI.item.iItem+1
          iCol = @pLVDI.item.iSubItem+1
       Case %NM_Click
          LVNT = Cb.LParam
          iRow = @LVNT.iItem+1
          iCol = @LVNT.iSubItem+1
       Case %NM_DblClk
          LVNT = Cb.LParam
          iRow = @LVNT.iItem+1
          iCol = @LVNT.iSubItem+1
       Case %LVN_ColumnClick
          Type Set LVData = Cb.NmHdr$(SizeOf(LVData))
          iRow = LVData.iItem+1
          iCol = LVData.iSubItem+1
       Case %LVN_ItemChanged  'Mouse Click or Keyboard Arrow will cause this
          pNMLV = Cb.LParam
          iRow  = @pNMLV.iItem+1
          iCol  = @pNMLV.iSubItem+1
    And, of course, if there's anything wrong with this code, feedback is welcome.

  • #2
    %NM_RCLICK, using same code.
    And then of course if LOCAL lplvcd AS NMLVCUSTOMDRAW PTR,
    then @lplvcd.nmcd.dwItemSpec is line and @lplvcd.iSubItem is column under %NM_CUSTOMDRAW


    • #3
      You can also at any time - that is, you don't have to wait for a notification - get the mouse position with GetCursorPos(), convert to client coordinates with ScreenToClient (), then use the ListView_HitTest macro (or LVM_HITTEST message) to get the item and subitem (if any) at the cursor.

      Your method in post #1 (LISTVIEW GET SELECT) of course does not work if the listview control is configured to support multiple selections OR if the cursor is not currently on the selected item. (depends on what you are doing).
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]