List control LVM_SETTOPINDEX required

The viewlist control has , which allows you to get the index of the topmost visible item. LVM_GETTOPINDEX

Now I need to set the topmost visible element, but surprisingly there is no message LVM_SETTOPINDEXthat would be natural.

Is there an easy way to set the topmost element?

My list control is always in report mode.

+4
source share
3 answers
  • Use LVM_GETITEMPOSITIONor LVM_GETITEMRECTto get the line item position.
  • Use LVM_SCROLLto scroll the list so that your item is top.
+2
source

-, . , , .

, , EnsureVisible(). , . EnsureVisible() . , , .

( ):

void CDlg::SetTopIndex(int top)
{
    int bottom = min(top + m_List.GetCountPerPage(), m_List.GetItemCount() - 1);
    m_List.SetRedraw(FALSE);
    m_List.EnsureVisible(bottom, TRUE);
    m_List.EnsureVisible(top, FALSE);
    m_List.SetRedraw(TRUE);
}
+2

:

void SetTopIndex(CListCtrl & listctrl, int topindex)
{
  int actualtopindex = listctrl.GetTopIndex();
  int horspacing;
  int lineheight;
  listctrl.GetItemSpacing(TRUE, &horspacing, &lineheight);

  CSize scrollsize(0, (topindex - actualtopindex) * lineheight);
  listctrl.Scroll(scrollsize);
}

.

, .

0
source

Source: https://habr.com/ru/post/1627307/


All Articles