OnButtonDelete() { POSITION pos = m_list.GetFirstSelectedItemPosition(); int idx = m_list.GetNextSelectedItem(pos); while (idx != -1){ LVITEM lvi; lvi.iItem = idx; lvi.iSubItem = 0; lvi.mask = LVIF_IMAGE; if (m_list.GetItem(&lvi)){ m_imgList.Remove(lvi.iImage); //同時刪除ImageList中的對應圖片 } m_list.DeleteItem(idx); idx = m_list.GetNextSelectedItem(pos); }
//需要先排序,再重繪,否則從中間刪除後該區域會空白,後面的記錄不會自動上移
m_list.Arrange(LVA_DEFAULT); m_list.RedrawItems(0, m_list.GetItemCount()); }