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. A CListCtrl Question

A CListCtrl Question

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 5 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.
  • J Offline
    J Offline
    Jethro63
    wrote on last edited by
    #1

    Greetings: I have a simple question: In a CListCtrl (configured in report mode), how do I simply select the item number that I want to appear at the top of the list. In other words, my list has, say, 1000 items and I would like to programatically scroll the list so that item number 500 is positioned at the top of the view. I do not necessarily need it to be selected or have the focus, I just want to position it. Thanks in advance, Mark

    J D Z B 4 Replies Last reply
    0
    • J Jethro63

      Greetings: I have a simple question: In a CListCtrl (configured in report mode), how do I simply select the item number that I want to appear at the top of the list. In other words, my list has, say, 1000 items and I would like to programatically scroll the list so that item number 500 is positioned at the top of the view. I do not necessarily need it to be selected or have the focus, I just want to position it. Thanks in advance, Mark

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #2

      Note the difference between the item indices CListCtrl saved and logical indices you used in putting which item on the top. CListCtrl always sets the top item's index to 1, which you cannot change. If you moved item #500 to the top, then its index will be changed to 1. CListCtrl maintains this indexing for user selection purpose. Thus, to programmatically move the items any way you want, you have to maintain your own logical indexing, as you do with sorting criteria.

      Best, Jun

      1 Reply Last reply
      0
      • J Jethro63

        Greetings: I have a simple question: In a CListCtrl (configured in report mode), how do I simply select the item number that I want to appear at the top of the list. In other words, my list has, say, 1000 items and I would like to programatically scroll the list so that item number 500 is positioned at the top of the view. I do not necessarily need it to be selected or have the focus, I just want to position it. Thanks in advance, Mark

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

        Can you make use of CListCtrl::EnsureVisible()?


        "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

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

        J 1 Reply Last reply
        0
        • D David Crow

          Can you make use of CListCtrl::EnsureVisible()?


          "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

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

          J Offline
          J Offline
          Jethro63
          wrote on last edited by
          #4

          Hi: I found that EnsureVisible will only make sure that you can SEE the item. It does not necessarily put it at the top of the view. If the box is currently showing item 0 at the top, and I ask to EnsureVisible for item 500, then it will only scroll enough to show item 500 at the BOTTOM of the view range. Its all very surprising. It seems like a pretty common need - to want to scroll the view range so that item N appears at the top of the view range - yet it is not easy to do... Cheers, Mark

          D 1 Reply Last reply
          0
          • J Jethro63

            Hi: I found that EnsureVisible will only make sure that you can SEE the item. It does not necessarily put it at the top of the view. If the box is currently showing item 0 at the top, and I ask to EnsureVisible for item 500, then it will only scroll enough to show item 500 at the BOTTOM of the view range. Its all very surprising. It seems like a pretty common need - to want to scroll the view range so that item N appears at the top of the view range - yet it is not easy to do... Cheers, Mark

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

            Jethro63 wrote:

            It seems like a pretty common need...

            This marks the first time I've heard of it.


            "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

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

            J 1 Reply Last reply
            0
            • D David Crow

              Jethro63 wrote:

              It seems like a pretty common need...

              This marks the first time I've heard of it.


              "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

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

              J Offline
              J Offline
              Jethro63
              wrote on last edited by
              #6

              Really? Then I've gone from surprised to utterly gob-smacked. Nobody ever wants the list control to just jump to record N? If I have a list of records that include, say, dates and times, and the user can search the list for the first record occuring on date XYZ or the nearest record after that. The program engine locates this record, its item #456. Wouldn't it be nice if the next thing that happens is that the list view range is repositioned with this record at the top? We have an inventory tracking system here that does that very thing. It doesn't produce a sub-set of the list (there's other search features that do that) it just adjusts the scroll position so that the record of interest is displayed at the top of the list. List Boxes and Combo Boxes are loaded with items and have a member to fetch the current position (GetCurSel) and adjust the current item displayed (SetCurSel). It seems odd that this was not extended to CListCtrl. Nevertheless, I am trying to extend CListCtrl into something with a few extra useful features. If I ever figure out how to do it, this will be one of the items that I add, even if I end up being the only person in explored space that appreciates it. :-D Thanks for your input. Mark

              D J 2 Replies Last reply
              0
              • J Jethro63

                Really? Then I've gone from surprised to utterly gob-smacked. Nobody ever wants the list control to just jump to record N? If I have a list of records that include, say, dates and times, and the user can search the list for the first record occuring on date XYZ or the nearest record after that. The program engine locates this record, its item #456. Wouldn't it be nice if the next thing that happens is that the list view range is repositioned with this record at the top? We have an inventory tracking system here that does that very thing. It doesn't produce a sub-set of the list (there's other search features that do that) it just adjusts the scroll position so that the record of interest is displayed at the top of the list. List Boxes and Combo Boxes are loaded with items and have a member to fetch the current position (GetCurSel) and adjust the current item displayed (SetCurSel). It seems odd that this was not extended to CListCtrl. Nevertheless, I am trying to extend CListCtrl into something with a few extra useful features. If I ever figure out how to do it, this will be one of the items that I add, even if I end up being the only person in explored space that appreciates it. :-D Thanks for your input. Mark

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

                Jethro63 wrote:

                Nobody ever wants the list control to just jump to record N?

                Sure, but not so far as requiring it be at the top of the list. As long as it's visible, and possibly selected, that's good enough.

                Jethro63 wrote:

                We have an inventory tracking system here that does that very thing.

                There's nothing wrong with custom controls. CP is full of 'em.


                "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

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

                J 1 Reply Last reply
                0
                • J Jethro63

                  Really? Then I've gone from surprised to utterly gob-smacked. Nobody ever wants the list control to just jump to record N? If I have a list of records that include, say, dates and times, and the user can search the list for the first record occuring on date XYZ or the nearest record after that. The program engine locates this record, its item #456. Wouldn't it be nice if the next thing that happens is that the list view range is repositioned with this record at the top? We have an inventory tracking system here that does that very thing. It doesn't produce a sub-set of the list (there's other search features that do that) it just adjusts the scroll position so that the record of interest is displayed at the top of the list. List Boxes and Combo Boxes are loaded with items and have a member to fetch the current position (GetCurSel) and adjust the current item displayed (SetCurSel). It seems odd that this was not extended to CListCtrl. Nevertheless, I am trying to extend CListCtrl into something with a few extra useful features. If I ever figure out how to do it, this will be one of the items that I add, even if I end up being the only person in explored space that appreciates it. :-D Thanks for your input. Mark

                  J Offline
                  J Offline
                  Jun Du
                  wrote on last edited by
                  #8

                  This requirement is not uncommon. Unfortunately, CListCtrl has no support for the feature. I have encountered and implemented a couple of such cases. It's not as difficult as you thought :)

                  Best, Jun

                  J 1 Reply Last reply
                  0
                  • D David Crow

                    Jethro63 wrote:

                    Nobody ever wants the list control to just jump to record N?

                    Sure, but not so far as requiring it be at the top of the list. As long as it's visible, and possibly selected, that's good enough.

                    Jethro63 wrote:

                    We have an inventory tracking system here that does that very thing.

                    There's nothing wrong with custom controls. CP is full of 'em.


                    "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

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

                    J Offline
                    J Offline
                    Jethro63
                    wrote on last edited by
                    #9

                    I get a lot of help from CP when I'm trying to figure out how to do things. But I don't like just taking somebody's solution and using it. I don't learn anything that way. I typically study a lot of different submissions and try to decide which way I would like to do it. Its slower but I feel better about it and I also stand a better chance of fixing things when they break. Cheers, Mark

                    1 Reply Last reply
                    0
                    • J Jun Du

                      This requirement is not uncommon. Unfortunately, CListCtrl has no support for the feature. I have encountered and implemented a couple of such cases. It's not as difficult as you thought :)

                      Best, Jun

                      J Offline
                      J Offline
                      Jethro63
                      wrote on last edited by
                      #10

                      Thanks Jun, I will keep plugging at it... Mark

                      1 Reply Last reply
                      0
                      • J Jethro63

                        Greetings: I have a simple question: In a CListCtrl (configured in report mode), how do I simply select the item number that I want to appear at the top of the list. In other words, my list has, say, 1000 items and I would like to programatically scroll the list so that item number 500 is positioned at the top of the view. I do not necessarily need it to be selected or have the focus, I just want to position it. Thanks in advance, Mark

                        Z Offline
                        Z Offline
                        Zac Howland
                        wrote on last edited by
                        #11

                        One sort of hack at it is to get the current number of items the list control displays (call it N), use Ensure Visible on the item you want to see and then on the item that is N-1 visible items away.

                        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                        1 Reply Last reply
                        0
                        • J Jethro63

                          Greetings: I have a simple question: In a CListCtrl (configured in report mode), how do I simply select the item number that I want to appear at the top of the list. In other words, my list has, say, 1000 items and I would like to programatically scroll the list so that item number 500 is positioned at the top of the view. I do not necessarily need it to be selected or have the focus, I just want to position it. Thanks in advance, Mark

                          B Offline
                          B Offline
                          bolivar123
                          wrote on last edited by
                          #12

                          Here is one way to move a specific list item to the top void CTestDlg::MoveItemToTop( int itemIndex ) { CRect topItemRect; CRect itemRect; //Figure out which item is currently at the top of the list int topIndex = m_ListCtrl.GetTopIndex(); //Get the bounding rectangle around the current top item m_ListCtrl.GetItemRect(topIndex+1,&topItemRect,LVIR_BOUNDS); //Get the bounding rectangle around the desired top item m_ListCtrl.GetItemRect(itemIndex,&itemRect,LVIR_BOUNDS); //Compute the y distance between the 2 items CSize size(0,itemRect.bottom-topItemRect.bottom); //Scroll the list m_ListCtrl.Scroll(size); }

                          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