Home > Software engineering >  Excuse me CListCtrl LVS_ICON mode, insert icon can not correctly according to insert location proble
Excuse me CListCtrl LVS_ICON mode, insert icon can not correctly according to insert location proble

Time:09-23

CListCtrl LVS_ICON, want to drag an icon to another icon before

But the MSDN display LVS_ICON order is not in order of the index,
This caused me insert drag the icon to release the mouse button icon,

InsertItem (m_nDropIndex, item. The pszText, item iImage); Return was successful, but does not display properly

If is LVS_AUTOARRANGE that there is no change,
If not LVS_AUTOARRANGE mode, this insert images are displayed in the back,

Icon mode is the CListCtrl LVS_ICON how to solve the problem of display after insert sorting? It is not according to the index sorting,

CodePudding user response:

 
//this function drops an item from a CListCtrl to a CListCtrl
Void CListCtrlView: : DropItemOnList (CListCtrl * pDropList)
{
//unhilite the drop target
PDropList - & gt; SetItemState (m_nDropIndex, 0, LVIS_DROPHILITED);

Char szLabel [256].
LV_ITEM lvi;

ZeroMemory (& amp; Lvi, sizeof (LV_ITEM));
Lvi. IItem=m_nDragIndex;
Lvi. Mask=LVIF_IMAGE | LVIF_TEXT;
Lvi. PszText=szLabel;
Lvi. CchTextMax=255;
//get the item that was dragged
VERIFY (m_List. The GetItem (& amp; Lvi));

//insert item into CListCtrl
Lvi. IItem=(m_nDropIndex==1)? PDropList - & gt; GetItemCount () : m_nDropIndex;
VERIFY (1!=pDropList - & gt; InsertItem (& amp; Lvi));
//select the new item we just inserted
VERIFY (pDropList - & gt; SetItemState (lvi) iItem, LVIS_SELECTED LVIS_SELECTED));
//delete the the original item (move operation)
VERIFY (m_List. Called DeleteItem (m_nDragIndex));
}
  • Related