Skip to content

Instantly share code, notes, and snippets.

@nibasya
Created February 8, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibasya/0206de16f789e7372e1b to your computer and use it in GitHub Desktop.
Save nibasya/0206de16f789e7372e1b to your computer and use it in GitHub Desktop.
Example of CListBox function which holds scroll bar position during insertion/ removal of item
void CDragDropListBox::SwapItem(int newIndex)
{
DWORD data;
CString str;
int top;
SetRedraw(FALSE);
top = GetTopIndex();
GetText(newIndex, str);
data = GetItemData(newIndex);
ASSERT(data != LB_ERR);
VERIFY(DeleteString(newIndex) != LB_ERR);
VERIFY(InsertString(m_TargetIndex, str) >= 0);
VERIFY(SetItemData(m_TargetIndex, data) != LB_ERR);
m_TargetIndex = newIndex;
SetTopIndex(top);
SetRedraw(TRUE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment