DeleteString(m_OldPosition+1);
this->SetCurSel(m_NewPosition);
file://设置移动条目的副值,如果删除或者添加一条记录,副值会随字符串一起移动
SetItemData(m_NewPosition,m_ItemData);
TRACE("%d%d%d%d%d%d%d%d",GetItemData(0),GetItemData(1),_
GetItemData(2),GetItemData(3),GetItemData(4),_
GetItemData(5),GetItemData(6),GetItemData(7));
}
else
{
InsertString(m_NewPosition+1,m_DragString);
DeleteString(m_OldPosition);
this->SetCurSel(m_NewPosition);
SetItemData(m_NewPosition,m_ItemData);
TRACE("%d%d%d%d%d%d%d%d",GetItemData(0),GetItemData(1),_
GetItemData(2),GetItemData(3),GetItemData(4),_
GetItemData(5),GetItemData(6),GetItemData(7));
}
}
}
}
void CMyListBox::OnMouseMove(UINT nFlags, CPoint point)
{
CListBox::OnMouseMove(nFlags, point);
if(m_LButtonDownFlag)
{
m_MouseMoveFlag = TRUE;
m_OldPosition = GetCurSel();
GetText(m_OldPosition,m_DragString);
try{
m_ItemData = GetItemData(m_OldPosition);
}
catch()
{
AfxMessageBox("Wrong!");
}
m_LButtonDownFlag = FALSE;
SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1));
}
}
实现了上面的代码后,我们就可以在列表框中随便改变我们的条目的顺序了,赶快试一下吧!在例程中弹出关于对话框,在列表中就可以改变顺序了。