Announcement

Collapse
No announcement yet.

Get Listview Row

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get Listview Row

    Hi,
    I have searched the forum for ways of getting the highlighted row in a listview and there are many, often complex methods. I am trying to get the index of a single row in one listview with %LVS_SINGLESEL set. I want to use this as the index to pull data from a 2d array to populate a second listview. Given its a single row what's the simplest way for a newbie please?
    Thanks!
    Attached Files

  • #2
    Get Listview Row

    Well, first off, you should have posted this in a different area. It seems you are using DDT so this message should have gone in the PowerBASIC for Windows or Dynamic Dialog Tools areas.

    The code you posted also doesn't have the %LVS_SINGLESEL style. You add the listview to the dialog with the default style and extended style. You then replace the extended style with %LVS_SINGLESEL but that is a regular style, not an extended style. I'm not sure what extended style you are getting by putting a 4 in the extended style but it doesn't really matter as you then immediately replace it with %LVS_EX_FULLROWSELECT.

    You would be better off dropping the two LISTVIEW SET STYLEXX commands and changing your CONTROL ADD LISTVIEW to:

    Code:
    CONTROL ADD LISTVIEW, hDlg, 100, "", 0, 100, 1200, 600, %LVS_REPORT OR %LVS_SHOWSELALWAYS OR %WS_TABSTOP OR %LVS_SINGLESEL, %WS_EX_LEFT OR %WS_EX_FULLROWSELECT
    Note that when you are not using the default style or extended style you need to put in all the styles and extended styles and not just the additional ones. So if you wanted to leave out the extended style above and wanted to add the full row select then you would use this code to make sure you don't mess up the default extended style:

    Code:
    LISTVIEW GET STYLEXX hDlg, 100 TO lStyle
    LISTVIEW SET STYLEXX hDlg, 100, lStyle OR %LVS_EX_FULLROWSELECT
    To find out which line is selected you can use:

    Code:
    LISTVIEW GET SELECT hDlg, 100 TO selrow
    Just add that line before your message box in your callback function. You might want to consider not making all your variables global but at least this message should hopefully answer your question.
    Last edited by Jeff Blakeney; 19 Nov 2009, 10:54 AM. Reason: Fixed typo on a command and added a missing [ for a code block.
    Jeff Blakeney

    Comment


    • #3
      It works and so simple..

      Thanks very much Jeff and your suggestions are noted!

      NB - Typo - For the benefit of any other newcomers to DDT, 'LISTSET' should be LISTVIEW SET in the example above.

      Comment


      • #4
        For SDK'ers...
        Code:
        ' returns: currently selected row; -1 if no row selected
        FUNCTION ListView_GetSelection (BYVAL hWnd AS LONG) AS LONG
          FUNCTION = SendMessage(hWnd, %LVM_GETNEXTITEM, -1, %LVNI_SELECTED)
        END FUNCTION
        [ADDED]
        ... Or DDT users, versions 8x or earlier
        Last edited by Michael Mattias; 19 Nov 2009, 12:21 PM.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Michael,

          You are off topic. This forum is for DDT code only. SDK code may only be posted if it enhances the functionality of DDT. The code you posted replaces DDT. You may post such code in the Windows or Programming forums, but not in the DDT forums.
          Sincerely,

          Steve Rossell
          PowerBASIC Staff

          Comment


          • #6
            Code:
            ' Hwnd [IN] Handle to dialog ([B]CBHNDL[/B]) 
            ' idlv [IN] Id of listview control added with [B]CONTROL ADD [/B]statement 
            ' returns: zero-based index of first selected row
            ' 
            FUNCTION  Listview_GetSelection (BYVAL hWnd AS LONG, BYVAL idLv AS LONG) AS LONG 
             LOCAL iRow AS LONG
              [B]CONTROL SEND[/B]  hWnd, idlv, %LVM_GETNEXTITEM, -1&, %LVNI_SELECTED TO iRow 
              FUNCTION = iRow  
            END FUNCTION
            HAPPY?
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Michael--

              This forum is reserved specifically for folks who use DDT functions primarily or exclusively. A few of them are even new to Windows programming, and we want to provide a place where they are comfortable using built-in functionality of the compiler. Whenever possible, it's very important to provide solutions which are entirely based upon DDT functionality. They can explore the WinAPI in due course.

              Please understand and respect the spirit of this forum and its participants? It would be best if we try to avoid any sarcasm.

              Thank you.

              Bob Zale
              PowerBASIC Inc.

              Comment

              Working...
              X