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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to enable auto scroll in a listbox?

How to enable auto scroll in a listbox?

Scheduled Pinned Locked Moved C#
tutorialquestion
8 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.
  • B Offline
    B Offline
    bar3000
    wrote on last edited by
    #1

    I have a list box in my app and i want it to autoscrol downward so it would always show the last item added. Thank you:)

    L L 2 Replies Last reply
    0
    • B bar3000

      I have a list box in my app and i want it to autoscrol downward so it would always show the last item added. Thank you:)

      L Offline
      L Offline
      Luis Alonso Ramos
      wrote on last edited by
      #2

      I think you have to do it manually. After adding an item to the end, call EnsureVisible[^].

      Luis Alonso Ramos Intelectix Chihuahua, Mexico My Blog!

      B 1 Reply Last reply
      0
      • L Luis Alonso Ramos

        I think you have to do it manually. After adding an item to the end, call EnsureVisible[^].

        Luis Alonso Ramos Intelectix Chihuahua, Mexico My Blog!

        B Offline
        B Offline
        bar3000
        wrote on last edited by
        #3

        didn't quite catch that... can u be more specific with the code?

        L 2 Replies Last reply
        0
        • B bar3000

          didn't quite catch that... can u be more specific with the code?

          L Offline
          L Offline
          Luis Alonso Ramos
          wrote on last edited by
          #4

          Something like this:

          int index = listBox.Items.Add("New item");
          listBox.EnsureVisible(index);  // Pass the index of the newly added item
          

          :) [EDIT: Wait!! I was thinking of ListView instead of ListBox. Sorry! I'm looking into it right now.]

          Luis Alonso Ramos Intelectix Chihuahua, Mexico My Blog!

          1 Reply Last reply
          0
          • B bar3000

            I have a list box in my app and i want it to autoscrol downward so it would always show the last item added. Thank you:)

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, whenever you change the number of items, do a myLB.TopIndex=myLB.Items.Count-1; :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


            modified on Sunday, June 12, 2011 8:31 AM

            B 1 Reply Last reply
            0
            • B bar3000

              didn't quite catch that... can u be more specific with the code?

              L Offline
              L Offline
              Luis Alonso Ramos
              wrote on last edited by
              #6

              Found it!! Use the TopIndex[^] property of the ListBox control. [EDIT: Oops, Luc beat me to it. :)]

              Luis Alonso Ramos Intelectix Chihuahua, Mexico My Blog!

              1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, whenever you change the number of items, do a myLB.TopIndex=myLB.Items.Count-1; :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                modified on Sunday, June 12, 2011 8:31 AM

                B Offline
                B Offline
                bar3000
                wrote on last edited by
                #7

                Thanks helped me a lot

                L 1 Reply Last reply
                0
                • B bar3000

                  Thanks helped me a lot

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  You're welcome. :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                  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