Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Automatic scrolling in ListBox

Automatic scrolling in ListBox

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Majid Shahabfar
    wrote on last edited by
    #1

    Hi there, I fill a ListBox (AddString(str)) from a loop. When ListBox become full the vertical scrollbar will be appeared. But I want to do somthing to move the scroll to down in order to the last item become appeared always. How can I do this? This functionality is very simple when we use CListControl, because there is a method called Scroll(...) in CListControl class for this reason. Thanks.

    V J 2 Replies Last reply
    0
    • M Majid Shahabfar

      Hi there, I fill a ListBox (AddString(str)) from a loop. When ListBox become full the vertical scrollbar will be appeared. But I want to do somthing to move the scroll to down in order to the last item become appeared always. How can I do this? This functionality is very simple when we use CListControl, because there is a method called Scroll(...) in CListControl class for this reason. Thanks.

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      you have to do it manually: something like: void DlgFlexListSelectValue::SetHorizontalScrollBar(){ //Next is to set the horizontal scroll bar //Find the longest string in the list box. CString str; CSize sz; int dx = 0; TEXTMETRIC tm; CDC* pDC = m_valueList.GetDC(); CFont* pFont = m_valueList.GetFont(); //Select the listbox font, save the old font CFont* pOldFont = pDC->SelectObject(pFont); //Get the text metrics for avg char width pDC->GetTextMetrics(&tm); for(int i = 0; i < m_valueList.GetCount(); i++){ m_valueList.GetText(i, str); sz = pDC->GetTextExtent(str); //Add the avg width to prevent clipping sz.cx += tm.tmAveCharWidth; if(sz.cx > dx){ dx = sz.cx; } //end if } //end for //Select the old font back into the DC pDC->SelectObject(pOldFont); m_valueList.ReleaseDC(pDC); //Set the horizontal extent so every character of all strings //can be scrolled to. m_valueList.SetHorizontalExtent(dx); } //end function SetHorizontalScrollBar call the function when you have loaded the listbox. it's on MSDN somewhere. good luck. No hurries, no worries.

      M 1 Reply Last reply
      0
      • M Majid Shahabfar

        Hi there, I fill a ListBox (AddString(str)) from a loop. When ListBox become full the vertical scrollbar will be appeared. But I want to do somthing to move the scroll to down in order to the last item become appeared always. How can I do this? This functionality is very simple when we use CListControl, because there is a method called Scroll(...) in CListControl class for this reason. Thanks.

        J Offline
        J Offline
        Jetli Jerry
        wrote on last edited by
        #3

        m_list.SetCurSel( m_list.AddString(s) ); will work for u. It will autimatically scroll to last item and will make is selected. Jetli Constant Thing In World Is Change.

        1 Reply Last reply
        0
        • V V 0

          you have to do it manually: something like: void DlgFlexListSelectValue::SetHorizontalScrollBar(){ //Next is to set the horizontal scroll bar //Find the longest string in the list box. CString str; CSize sz; int dx = 0; TEXTMETRIC tm; CDC* pDC = m_valueList.GetDC(); CFont* pFont = m_valueList.GetFont(); //Select the listbox font, save the old font CFont* pOldFont = pDC->SelectObject(pFont); //Get the text metrics for avg char width pDC->GetTextMetrics(&tm); for(int i = 0; i < m_valueList.GetCount(); i++){ m_valueList.GetText(i, str); sz = pDC->GetTextExtent(str); //Add the avg width to prevent clipping sz.cx += tm.tmAveCharWidth; if(sz.cx > dx){ dx = sz.cx; } //end if } //end for //Select the old font back into the DC pDC->SelectObject(pOldFont); m_valueList.ReleaseDC(pDC); //Set the horizontal extent so every character of all strings //can be scrolled to. m_valueList.SetHorizontalExtent(dx); } //end function SetHorizontalScrollBar call the function when you have loaded the listbox. it's on MSDN somewhere. good luck. No hurries, no worries.

          M Offline
          M Offline
          Majid Shahabfar
          wrote on last edited by
          #4

          Thank you. but I don't have problem with horizontal scrolling

          V 1 Reply Last reply
          0
          • M Majid Shahabfar

            Thank you. but I don't have problem with horizontal scrolling

            V Offline
            V Offline
            V 0
            wrote on last edited by
            #5

            idd, I misread, my apologies :doh:. good luck though. PS: there should be a function like SetScrollPos or something. No hurries, no worries.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups