problems restoring previous scrollbar/window position with CListBox (newbie alert)

Hi, I'm using a single CListBox object to display multiple datasets. When a 
different dataset is selected I save the current scroll/selection using the 
GetScrollPos/GetCurSel methods and when the same dataset is selected again I 
want to rebuild the ListBox and restore the previous scroll/selection.

Restoring the selection with SetCurSel works fine and restoring the 
scrollbar positions with SetScrollPos also works fine but the ListBox 
doesn't actually scroll to the restored positions (it just stays at the 
start of the list unless there was a selected item, in which case it scrolls 
so that the selected item is visible but the window is not in the original 
position).

I've tried using the ScrollWindow method to move the ListBox view to the 
correct position but this produces some weird results like ListBox contents 
being drawn outside the the appropriate window rectangle and corrupting the 
display.

The strange thing is that SetTopIndex works fine - it restores the vertical 
window position and scrollbar perfectly but I can't restore the previous 
horizontal position using this function.

The sequence of events leading to the restore operations is this:

CTabCtrl is clicked and the message handler calls some code that resets the 
CListBox contents, rebuilds all the listbox entries and recalculates the 
scroll extents for the new data.  Then I try to restore the previous 
window/scroll/selection.

Can anyone help?

Kind Regards,

Karl.
 


0
me5306 (285)
1/12/2005 4:49:48 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
528 Views

Similar Articles

[PageSpeed] 33

CListBox::SelectString -

Remarks in MSDN says:
The list box is scrolled, if necessary, to bring the selected item into 
view.
Doesnt that work for you?


"me" <me@here.com> wrote in message 
news:cs3kfc$e8j$1@sparta.btinternet.com...
> Hi, I'm using a single CListBox object to display multiple datasets. When 
> a different dataset is selected I save the current scroll/selection using 
> the GetScrollPos/GetCurSel methods and when the same dataset is selected 
> again I want to rebuild the ListBox and restore the previous 
> scroll/selection.
>
> Restoring the selection with SetCurSel works fine and restoring the 
> scrollbar positions with SetScrollPos also works fine but the ListBox 
> doesn't actually scroll to the restored positions (it just stays at the 
> start of the list unless there was a selected item, in which case it 
> scrolls so that the selected item is visible but the window is not in the 
> original position).
>
> I've tried using the ScrollWindow method to move the ListBox view to the 
> correct position but this produces some weird results like ListBox 
> contents being drawn outside the the appropriate window rectangle and 
> corrupting the display.
>
> The strange thing is that SetTopIndex works fine - it restores the 
> vertical window position and scrollbar perfectly but I can't restore the 
> previous horizontal position using this function.
>
> The sequence of events leading to the restore operations is this:
>
> CTabCtrl is clicked and the message handler calls some code that resets 
> the CListBox contents, rebuilds all the listbox entries and recalculates 
> the scroll extents for the new data.  Then I try to restore the previous 
> window/scroll/selection.
>
> Can anyone help?
>
> Kind Regards,
>
> Karl.
>
>
> 


0
Priyesh
1/12/2005 5:17:56 PM
You could look into CListBox::SetTopIndex as well
HTH

"me" <me@here.com> wrote in message 
news:cs3kfc$e8j$1@sparta.btinternet.com...
> Hi, I'm using a single CListBox object to display multiple datasets. When 
> a different dataset is selected I save the current scroll/selection using 
> the GetScrollPos/GetCurSel methods and when the same dataset is selected 
> again I want to rebuild the ListBox and restore the previous 
> scroll/selection.
>
> Restoring the selection with SetCurSel works fine and restoring the 
> scrollbar positions with SetScrollPos also works fine but the ListBox 
> doesn't actually scroll to the restored positions (it just stays at the 
> start of the list unless there was a selected item, in which case it 
> scrolls so that the selected item is visible but the window is not in the 
> original position).
>
> I've tried using the ScrollWindow method to move the ListBox view to the 
> correct position but this produces some weird results like ListBox 
> contents being drawn outside the the appropriate window rectangle and 
> corrupting the display.
>
> The strange thing is that SetTopIndex works fine - it restores the 
> vertical window position and scrollbar perfectly but I can't restore the 
> previous horizontal position using this function.
>
> The sequence of events leading to the restore operations is this:
>
> CTabCtrl is clicked and the message handler calls some code that resets 
> the CListBox contents, rebuilds all the listbox entries and recalculates 
> the scroll extents for the new data.  Then I try to restore the previous 
> window/scroll/selection.
>
> Can anyone help?
>
> Kind Regards,
>
> Karl.
>
>
> 


0
Priyesh
1/12/2005 5:19:45 PM
It "kind of" works - The ListBox window will scroll to a position where the 
selected item is visible but for my purposes I want the window to be in 
exactly the same scroll position it was when a particular dataset was last 
viewed.

Using SelectString doesn't do this, in fact if an item is selected and then 
the listbox is scrolled to a different part of the list, this technique will 
give completely the wrong results.

The function SetTopIndex actually works perfectly for my purposes but it 
only works for the vertical scroll axis and I was wondering if anyone knows 
the details of manually setting the scroll position of a list box?

Karl.



"Priyesh" <Priyesh_at_do_not_reply> wrote in message 
news:%23BrOqtM%23EHA.2180@TK2MSFTNGP12.phx.gbl...
> CListBox::SelectString -
>
> Remarks in MSDN says:
> The list box is scrolled, if necessary, to bring the selected item into 
> view.
> Doesnt that work for you?
>
>
> "me" <me@here.com> wrote in message 
> news:cs3kfc$e8j$1@sparta.btinternet.com...
>> Hi, I'm using a single CListBox object to display multiple datasets. When 
>> a different dataset is selected I save the current scroll/selection using 
>> the GetScrollPos/GetCurSel methods and when the same dataset is selected 
>> again I want to rebuild the ListBox and restore the previous 
>> scroll/selection.
>>
>> Restoring the selection with SetCurSel works fine and restoring the 
>> scrollbar positions with SetScrollPos also works fine but the ListBox 
>> doesn't actually scroll to the restored positions (it just stays at the 
>> start of the list unless there was a selected item, in which case it 
>> scrolls so that the selected item is visible but the window is not in the 
>> original position).
>>
>> I've tried using the ScrollWindow method to move the ListBox view to the 
>> correct position but this produces some weird results like ListBox 
>> contents being drawn outside the the appropriate window rectangle and 
>> corrupting the display.
>>
>> The strange thing is that SetTopIndex works fine - it restores the 
>> vertical window position and scrollbar perfectly but I can't restore the 
>> previous horizontal position using this function.
>>
>> The sequence of events leading to the restore operations is this:
>>
>> CTabCtrl is clicked and the message handler calls some code that resets 
>> the CListBox contents, rebuilds all the listbox entries and recalculates 
>> the scroll extents for the new data.  Then I try to restore the previous 
>> window/scroll/selection.
>>
>> Can anyone help?
>>
>> Kind Regards,
>>
>> Karl.
>>
>>
>>
>
> 


0
me5306 (285)
1/13/2005 2:25:30 AM
Yep, SetTopIndex works fine but only for the vertical scroll axis.  Is there 
anything for the horizontal axis that will do the same job?

Karl.

"Priyesh" <Priyesh_at_do_not_reply> wrote in message 
news:Oj5CsuM%23EHA.2788@TK2MSFTNGP15.phx.gbl...
> You could look into CListBox::SetTopIndex as well
> HTH
>
> "me" <me@here.com> wrote in message 
> news:cs3kfc$e8j$1@sparta.btinternet.com...
>> Hi, I'm using a single CListBox object to display multiple datasets. When 
>> a different dataset is selected I save the current scroll/selection using 
>> the GetScrollPos/GetCurSel methods and when the same dataset is selected 
>> again I want to rebuild the ListBox and restore the previous 
>> scroll/selection.
>>
>> Restoring the selection with SetCurSel works fine and restoring the 
>> scrollbar positions with SetScrollPos also works fine but the ListBox 
>> doesn't actually scroll to the restored positions (it just stays at the 
>> start of the list unless there was a selected item, in which case it 
>> scrolls so that the selected item is visible but the window is not in the 
>> original position).
>>
>> I've tried using the ScrollWindow method to move the ListBox view to the 
>> correct position but this produces some weird results like ListBox 
>> contents being drawn outside the the appropriate window rectangle and 
>> corrupting the display.
>>
>> The strange thing is that SetTopIndex works fine - it restores the 
>> vertical window position and scrollbar perfectly but I can't restore the 
>> previous horizontal position using this function.
>>
>> The sequence of events leading to the restore operations is this:
>>
>> CTabCtrl is clicked and the message handler calls some code that resets 
>> the CListBox contents, rebuilds all the listbox entries and recalculates 
>> the scroll extents for the new data.  Then I try to restore the previous 
>> window/scroll/selection.
>>
>> Can anyone help?
>>
>> Kind Regards,
>>
>> Karl.
>>
>>
>>
>
> 


0
me5306 (285)
1/13/2005 2:26:28 AM
Reply:

Similar Artilces: