MFC之CListCtrl删除一行数据

void thirdlyDlg::OnBnClickedButton3Delete()
{
 // TODO: 在此添加控件通知处理程序代码
 POSITION pos = m_oListScore.GetFirstSelectedItemPosition();
 int idx = m_oListScore.GetNextSelectedItem(pos);
 while (idx != -1){
  LVITEM lvi;

  lvi.iItem = idx;

  lvi.iSubItem = 0;

  lvi.mask = LVIF_IMAGE;

  m_oListScore.DeleteItem(idx);

  idx = m_oListScore.GetNextSelectedItem(pos);
 }
 //需要先排序,再重绘,否则从中间删除后该区域会空白,后面的记录不会自动上移
 m_oListScore.Arrange(LVA_DEFAULT);
 m_oListScore.RedrawItems(0, m_oListScore.GetItemCount());

}

 在控件里添加上述代码,m_oListScore是listcontrl变量

你可能感兴趣的:(MFC)