A CListCtrl Question
-
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
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
-
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
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
-
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
-
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
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
-
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
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); }