List Control Item Height [modified]
-
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
-
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
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
-
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
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
-
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
//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.
-
//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.
-
//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.
Can't you use SetTopIndex() instead?
- S 50 cups of coffee and you know it's on!
-
Can't you use SetTopIndex() instead?
- S 50 cups of coffee and you know it's on!
-
Ooops, thought you we're using CListBox. Never mind....
- S 50 cups of coffee and you know it's on!
-
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!
-
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!
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