Announcement

Collapse
No announcement yet.

how to set Autoscroll in Listbox control

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

  • how to set Autoscroll in Listbox control

    In main code:
    Code:
       ListboxFlags = %ws_child Or %ws_visible Or %ws_tabstop Or %ws_vscroll Or %lbs_multiplesel Or %lbs_extendedsel
       'ListboxFlags = ListboxFlags Or %es_autovscroll    ' Or %lbs_disablenoscroll  
    
       Control Add ListBox, hDlg, %LISTBOX, , 5, 5, 490, 50, ListboxFlags, %ws_ex_clientedge
    I know, ES_AUTOSCROLL doesn't work with the listbox... but I had to try!


    In the dialog's callback:
    Code:
             ListboxCount = SendMessage(hList, %LB_GETCOUNT,  0, 0) 'Ask listbox for items count
             SendMessage(hList, %LB_ADDSTRING, ListboxCount, StrPtr(sBuffer)) 'Add message to listbox
             SendMessage hList, %LB_SETCURSEL, ListboxCount, 0 'Go to last listbox position
    As lines are added and fill the box, the Vertical scrollbar appears (as desired).

    I'd like the text to scroll so that the last line added is displayed as the last line in the box. This will scroll the rest "upward"...

    Although I've read SDK and Help info, searched the fourm, and tried various values, I'm presuming there's something in the LB_SETCURSEL message that I haven't found yet.

    Can anyone provide me a pointer to relevant information?
    Thanks!
    Last edited by John Montenigro; 23 Feb 2009, 01:32 PM.

  • #2
    %lb_setcaretindex
    Rick Angell

    Comment


    • #3
      ListView_EnsureVisible ()

      As demo'd here:
      Use Listview control as a console. September 13 2003.

      Oops, that's for a listVIEW, not a listBOX.

      Wait a minute, this is forgiveable... thread subject says listVIEW, but the fine print says listBOX.
      Last edited by Michael Mattias; 23 Feb 2009, 11:07 AM.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Richard,

        Here's my edited code:

        Code:
                       ListboxCount = SendMessage(hList, %LB_GETCOUNT,  0, 0) 'Ask listbox for items count
                       SendMessage(hList, %LB_ADDSTRING, ListboxCount, StrPtr(sBuffer)) 'Add message to listbox
                      ' SendMessage hList, %LB_SETCURSEL, ListboxCount, 0 'Go to last listbox position      
                       SendMessage hList, %lb_setcaretindex, ListboxCount+1, 0  'yay!!
        And by adding 1 to ListboxCount, the dotted rectangle does not display.

        Problem solved! Thanks!




        Michael,

        Sorry! I'd edit the thread name if I could, but I don't know how.

        But no good effort is wasted - ListVIEWs are close on my list of things to learn, so I'll check out your code reference soon.

        Thanks!

        Comment


        • #5
          Got to edit your thread, then advanced mode. It will let you edit the thread title.

          Comment


          • #6
            Done! Hmm... but even after a refresh, it's not showing up changed on the main forum page... Oh, well - at least the proper subject is now on the first message.

            thanks for that info, Gary!
            Last edited by John Montenigro; 23 Feb 2009, 01:36 PM.

            Comment


            • #7
              Without winapi:
              Code:
              LISTBOX GET COUNT hDlg???, %LISTBOX TO ListboxCount&
              LISTBOX SELECT    hDlg???, %LISTBOX,   ListboxCount&
              LISTBOX UNSELECT  hDlg???, %LISTBOX,   ListboxCount&

              Comment

              Working...
              X