Automatic scrolling in ListBox
-
Hi there, I fill a ListBox (AddString(str)) from a loop. When ListBox become full the vertical scrollbar will be appeared. But I want to do somthing to move the scroll to down in order to the last item become appeared always. How can I do this? This functionality is very simple when we use CListControl, because there is a method called Scroll(...) in CListControl class for this reason. Thanks.
-
Hi there, I fill a ListBox (AddString(str)) from a loop. When ListBox become full the vertical scrollbar will be appeared. But I want to do somthing to move the scroll to down in order to the last item become appeared always. How can I do this? This functionality is very simple when we use CListControl, because there is a method called Scroll(...) in CListControl class for this reason. Thanks.
you have to do it manually: something like:
void DlgFlexListSelectValue::SetHorizontalScrollBar(){ //Next is to set the horizontal scroll bar //Find the longest string in the list box. CString str; CSize sz; int dx = 0; TEXTMETRIC tm; CDC* pDC = m_valueList.GetDC(); CFont* pFont = m_valueList.GetFont(); //Select the listbox font, save the old font CFont* pOldFont = pDC->SelectObject(pFont); //Get the text metrics for avg char width pDC->GetTextMetrics(&tm); for(int i = 0; i < m_valueList.GetCount(); i++){ m_valueList.GetText(i, str); sz = pDC->GetTextExtent(str); //Add the avg width to prevent clipping sz.cx += tm.tmAveCharWidth; if(sz.cx > dx){ dx = sz.cx; } //end if } //end for //Select the old font back into the DC pDC->SelectObject(pOldFont); m_valueList.ReleaseDC(pDC); //Set the horizontal extent so every character of all strings //can be scrolled to. m_valueList.SetHorizontalExtent(dx); } //end function SetHorizontalScrollBar
call the function when you have loaded the listbox. it's on MSDN somewhere. good luck. No hurries, no worries. -
Hi there, I fill a ListBox (AddString(str)) from a loop. When ListBox become full the vertical scrollbar will be appeared. But I want to do somthing to move the scroll to down in order to the last item become appeared always. How can I do this? This functionality is very simple when we use CListControl, because there is a method called Scroll(...) in CListControl class for this reason. Thanks.
m_list.SetCurSel( m_list.AddString(s) ); will work for u. It will autimatically scroll to last item and will make is selected. Jetli Constant Thing In World Is Change.
-
you have to do it manually: something like:
void DlgFlexListSelectValue::SetHorizontalScrollBar(){ //Next is to set the horizontal scroll bar //Find the longest string in the list box. CString str; CSize sz; int dx = 0; TEXTMETRIC tm; CDC* pDC = m_valueList.GetDC(); CFont* pFont = m_valueList.GetFont(); //Select the listbox font, save the old font CFont* pOldFont = pDC->SelectObject(pFont); //Get the text metrics for avg char width pDC->GetTextMetrics(&tm); for(int i = 0; i < m_valueList.GetCount(); i++){ m_valueList.GetText(i, str); sz = pDC->GetTextExtent(str); //Add the avg width to prevent clipping sz.cx += tm.tmAveCharWidth; if(sz.cx > dx){ dx = sz.cx; } //end if } //end for //Select the old font back into the DC pDC->SelectObject(pOldFont); m_valueList.ReleaseDC(pDC); //Set the horizontal extent so every character of all strings //can be scrolled to. m_valueList.SetHorizontalExtent(dx); } //end function SetHorizontalScrollBar
call the function when you have loaded the listbox. it's on MSDN somewhere. good luck. No hurries, no worries.Thank you. but I don't have problem with horizontal scrolling
-
Thank you. but I don't have problem with horizontal scrolling