Re: last added line always visible in listbox
This is a code snippet, but this is a way I use listboxes to do status. I
always have a check box to stop it from autoscrolling but you could do
something like if the focus is not on the bottom line it would stop (this is
how VS works while compiling for example). This one also turns on the
horizontal scroll bar if some text gets too wide ...
void CMyDlg::AddStatusMessage(LPCTSTR szMsg)
{
// Set the horizontal scroll
int oldwidth = m_cStatus.GetHorizontalExtent();
CDC* pDC = m_cStatus.GetWindowDC();
if (pDC) {
int newwidth = (int)(pDC->GetTextExtent(szMsg,
(int)_tcslen(szMsg)).cx);
m_cStatus.ReleaseDC(pDC);
if (newwidth > oldwidth)
m_cStatus.SetHorizontalExtent(newwidth);
}
// Add the new one at the end
m_cStatus.AddString(szMsg);
if(m_bAutoScrollStatus) {
// Keep the last one in view
m_cStatus.SetTopIndex(m_cStatus.GetCount()-1);
}
}
Tom
"tio" <tomjey@wp.pl> wrote in message
news:1155909533.593851.160030@m73g2000cwd.googlegroups.com...
Hello
I add new lines to listbox using AddString();
I want that last added line to listbox was visible when I put many many
new lines.
Now I always see top of list even I add many lines.
Is some simple way to do this ?