Click to See Complete Forum and Search --> : Automatic Scrolling in CListBox


Jim Shaw
May 4th, 1999, 03:45 PM
I have a ListBox control in a dialog application, and I am programmatically adding lines to the listbox. I want the listbox to automatically scroll down as each new line is added by the program. I created the following function to do this:

void CPVSMainDlg::ScrollWithIt(CListBox& lbox)
{
int limit;

limit = lbox.GetScrollLimit(SB_VERT);

lbox.SetScrollPos(SB_VERT, limit, TRUE);
lbox.UpdateWindow();
}

Note: CPVSMainDlg is my main dialog box and I am passing the listbox to a member function that I created.

This works partially in that the scrollbar on the listbox does go down to the bottom. The problem is that the listbox window itself does not actually scroll. I have tried many things and it is probably something simple that I am missing, but I just can't seem to get it to work. Anyone have any ideas??? Thanks in advance.

Howard Birkett
May 4th, 1999, 06:11 PM
If you know the index of the added item - returned from AddString() - use SetTopIndex()

Howard