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. List Control Item Height [modified]

List Control Item Height [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 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.
  • S Offline
    S Offline
    switang
    wrote on last edited by
    #1

    What's the best way to get the item height in a list control? GetItemRect()? Assuming there are items. Trying to restore a scroll position. Since Scoll() divides by the height of the control line... Thanks. -- modified at 12:45 Thursday 7th December, 2006

    D S 2 Replies Last reply
    0
    • S switang

      What's the best way to get the item height in a list control? GetItemRect()? Assuming there are items. Trying to restore a scroll position. Since Scoll() divides by the height of the control line... Thanks. -- modified at 12:45 Thursday 7th December, 2006

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Are you trying to ensure that a previously-selected item is visible the next time your application runs?


      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

      "Judge not by the eye but by the heart." - Native American Proverb

      S 1 Reply Last reply
      0
      • D David Crow

        Are you trying to ensure that a previously-selected item is visible the next time your application runs?


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        S Offline
        S Offline
        switang
        wrote on last edited by
        #3

        No, my listctrl is a reflection of an internal list. When I update the listctrl I clear it first and just add the items that are in the list. Any data updates are performed on the internal list. I hope to only update the modifed items in the future, but for now, I am clearing the listctrl. And that's why I need the restore the scroll position. I'm currently trying to use the item height times the top item's index that I store, and I pass that to Scroll() in the CSize() parameter. -- modified at 15:00 Thursday 7th December, 2006

        1 Reply Last reply
        0
        • S switang

          What's the best way to get the item height in a list control? GetItemRect()? Assuming there are items. Trying to restore a scroll position. Since Scoll() divides by the height of the control line... Thanks. -- modified at 12:45 Thursday 7th December, 2006

          S Offline
          S Offline
          switang
          wrote on last edited by
          #4

          //Store the top item position topItemIndex = listControl->GetTopIndex(); ... //Scroll window back to original position, assuming starting at 0 if (listControl->GetItemCount() > 0) { CRect itemRect; listControl->GetItemRect(0, itemRect, LVIR_LABEL); int x = 0; x = listControl->Scroll(CSize(0, topItemIndex * itemRect.Height())); _ASSERT(x != 0); } This seems to work except after to item 500+ it will scroll too far up or all the way to the beginning.

          S Steve EcholsS 2 Replies Last reply
          0
          • S switang

            //Store the top item position topItemIndex = listControl->GetTopIndex(); ... //Scroll window back to original position, assuming starting at 0 if (listControl->GetItemCount() > 0) { CRect itemRect; listControl->GetItemRect(0, itemRect, LVIR_LABEL); int x = 0; x = listControl->Scroll(CSize(0, topItemIndex * itemRect.Height())); _ASSERT(x != 0); } This seems to work except after to item 500+ it will scroll too far up or all the way to the beginning.

            S Offline
            S Offline
            switang
            wrote on last edited by
            #5

            Anyone know if there is limit as to how many Scroll() can scroll?

            1 Reply Last reply
            0
            • S switang

              //Store the top item position topItemIndex = listControl->GetTopIndex(); ... //Scroll window back to original position, assuming starting at 0 if (listControl->GetItemCount() > 0) { CRect itemRect; listControl->GetItemRect(0, itemRect, LVIR_LABEL); int x = 0; x = listControl->Scroll(CSize(0, topItemIndex * itemRect.Height())); _ASSERT(x != 0); } This seems to work except after to item 500+ it will scroll too far up or all the way to the beginning.

              Steve EcholsS Offline
              Steve EcholsS Offline
              Steve Echols
              wrote on last edited by
              #6

              Can't you use SetTopIndex() instead?


              - S 50 cups of coffee and you know it's on!

              • S
                50 cups of coffee and you know it's on!
                Code, follow, or get out of the way.
              S 1 Reply Last reply
              0
              • Steve EcholsS Steve Echols

                Can't you use SetTopIndex() instead?


                - S 50 cups of coffee and you know it's on!

                S Offline
                S Offline
                switang
                wrote on last edited by
                #7

                Don't see a SetTopIndex() for CListCtrl

                Steve EcholsS 2 Replies Last reply
                0
                • S switang

                  Don't see a SetTopIndex() for CListCtrl

                  Steve EcholsS Offline
                  Steve EcholsS Offline
                  Steve Echols
                  wrote on last edited by
                  #8

                  Ooops, thought you we're using CListBox. Never mind....


                  - S 50 cups of coffee and you know it's on!

                  • S
                    50 cups of coffee and you know it's on!
                    Code, follow, or get out of the way.
                  1 Reply Last reply
                  0
                  • S switang

                    Don't see a SetTopIndex() for CListCtrl

                    Steve EcholsS Offline
                    Steve EcholsS Offline
                    Steve Echols
                    wrote on last edited by
                    #9

                    I think EnsureVisible() could work for you. Save the top index using GetTopIndex, then use EnsureVisible( nTopIndex, FALSE ) to scroll it into view.


                    - S 50 cups of coffee and you know it's on!

                    • S
                      50 cups of coffee and you know it's on!
                      Code, follow, or get out of the way.
                    S 1 Reply Last reply
                    0
                    • Steve EcholsS Steve Echols

                      I think EnsureVisible() could work for you. Save the top index using GetTopIndex, then use EnsureVisible( nTopIndex, FALSE ) to scroll it into view.


                      - S 50 cups of coffee and you know it's on!

                      S Offline
                      S Offline
                      switang
                      wrote on last edited by
                      #10

                      Bless you! It only scrolls until the index is visible on the bottom, so I add the value from GetCountPerPage() minus one: ... result = listControl->EnsureVisible( topItemIndex + listControl->GetCountPerPage() - 1, FALSE); _ASSERT(result = TRUE); ... Seems to work, even on 1000+ items. Hopefully I'll get the time to rewrite to where only modified items will be updated... :laugh: -- modified at 10:41 Friday 8th December, 2006

                      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