How move a CListCtrl item?!
-
Hi all, I have a CListCtrl that contains some only-text item, I want to move(pressing a button) the selected item up/down in the list but how? I have to use "SetItemPosition"? There wasn't a method to move the item of only one position? Help me please, and sorry for my english! Thanks.:-O
-
Hi all, I have a CListCtrl that contains some only-text item, I want to move(pressing a button) the selected item up/down in the list but how? I have to use "SetItemPosition"? There wasn't a method to move the item of only one position? Help me please, and sorry for my english! Thanks.:-O
When you are in Report mode, something like this SwapRows function should help: void CMyListCtrl::SwapRows(int row1, int row2) { // rowText will hold all column text for one row CStringArray rowText; LV_ITEM lvitemrow1, lvitemrow2; int nColCount = GetColumnCount(); rowText.SetSize( nColCount ); int i; for( i=0; i < nColCount; i++) rowText[i] = GetItemText(row1, i); lvitemrow1.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_STATE; lvitemrow1.iItem = row1; lvitemrow1.iSubItem = 0; lvitemrow1.stateMask = LVIS_CUT | LVIS_DROPHILITED | LVIS_FOCUSED | LVIS_SELECTED | LVIS_OVERLAYMASK | LVIS_STATEIMAGEMASK; lvitemrow2 = lvitemrow1; lvitemrow2.iItem = row2; GetItem( &lvitemrow1 ); GetItem( &lvitemrow2 ); for( i=0; i< nColCount; i++) SetItemText(row1, i, GetItemText(row2, i) ); lvitemrow2.iItem = row1; SetItem( &lvitemrow2 ); for( i=0; i< nColCount; i++) SetItemText(row2, i, rowText[i]); lvitemrow1.iItem = row2; SetItem( &lvitemrow1 ); } WM_HOPEITHELPED