안녕하세요

프로그램 과정에서 막혔던 문제들에 대한 해결책 정리


페이지 목록

2014년 11월 21일 금요일

[MFC] Listctrl Item 간 위치 변경

첨부화일을 참고하세요....... void MoveTo(CListCtrl* pList, int index1, int index2) // index1 < index2 이고.. { // index1의 item을 index2+1로 이동후 index1의 item은 지움.. if(index1==index2) return; int idx1 = index1; int idx2 = index2; if(index1 > index2) { idx1 = index2; idx2 = index1; } int nCount = pList->GetHeaderCtrl()->GetItemCount(); CString str; str = pList->GetItemText(idx1,0); pList->InsertItem(idx2+1, str); for(int k=1; kGetItemText(idx1,k); pList->SetItemText(idx2+1, k,str); } pList->DeleteItem(idx1); } void CABC11Dlg::OnButtonMoveup() { // TODO: Add your control notification handler code here CListCtrl *pList = &m_list; ///////////// POSITION pos = pList->GetFirstSelectedItemPosition(); if(pos == NULL) return; int PreIndex=-1; int Index; while(pos) { Index = pList->GetNextSelectedItem(pos); if( PreIndex+1 != Index) { MoveTo(pList, Index, Index-1); pList->SetItemState(Index-1, LVIS_SELECTED, LVIS_SELECTED); PreIndex = Index-1; } else PreIndex = Index; } } void CABC11Dlg::OnButtonMovedown() { // TODO: Add your control notification handler code here CListCtrl *pList = &m_list; //////// POSITION pos = pList->GetFirstSelectedItemPosition(); if(pos == NULL) return; vector IndexData; while(pos) { int Index = pList->GetNextSelectedItem(pos); IndexData.push_back(Index); } int size = IndexData.size()-1; int PreIndex=pList->GetItemCount(); int Index; for( ;0<=size ; --size) { Index = IndexData[size]; if(Index+1 != PreIndex) { MoveTo(pList, Index, Index+1); pList->SetItemState(Index+1, LVIS_SELECTED, LVIS_SELECTED); PreIndex = Index+1; } else PreIndex = Index; } } Vㅔ리 굳 출처: http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=50&MaeulNo=20&no=874306&ref=874281