본문 바로가기
MFC

CListCtrl DeleteItem

by leo21c 2018. 5. 15.
SMALL

https://msdn.microsoft.com/ko-kr/library/84fyba4z.aspx


List View에서 특정 Row을 삭제할 때 주의를 해야 한다.

아래와 같이 DeleteItem에 i번째  Row을 삭제하라고 처리하면 정상적으로 삭제가 되지 않는다.

int nCount = m_myListCtrl.GetItemCount();


// Delete all of the items from the list view control.

for (int i=0; i < nCount; i++)

{

m_myListCtrl.DeleteItem(i);


n번째부터 m번째까지 삭제를 한다면 아래와 같이 구현을 해야 정상적으로 처리된다.

n번째를 m-n번 만큼 삭제를 하면 n부터 m까지 Row가 삭제된다.


int nCount = m_myListCtrl.GetItemCount();

int nRealCount = m - n;

// Delete all of the items from the list view control.

for (int i=0; i < nRealCount && m < nCount; i++)

{

m_myListCtrl.DeleteItem(n);



LIST