//----------------------------------------------------
// Des: Delete a CListCtrl Column,
// param: nIndex -the column index
// note that you cann't use DeleteColumn(0),
// when you want to delete first column.
//----------------------------------------------------
void DeleteListColumn(CListCtrl *pList, int nIndex)
{
CHeaderCtrl *pHeader = pList->GetHeaderCtrl();
int nHeadCount = pHeader->GetItemCount();
if(nIndex > 0 || nHeadCount == 1) //not first column or not one column
{ //use DeleteColumn(i)
pList->DeleteColumn(nIndex);
return;
}
LV_COLUMN curItem; //column struct
curItem.mask = LVCF_TEXT|LVCF_WIDTH;
char str[64];
int nCx= 0;
memset(str, 0, 64);
curItem.pszText=str;
curItem.cchTextMax=64;
curItem.cx = nCx;
for(int n = 1; n < nHeadCount; n++) //move column 1--n to 0-->n-1
{
pList->GetColumn(n, &curItem); //get next column
pList->SetColumn(n-1, &curItem); //move to previous
for(int i = 0; i < pList->GetItemCount(); i++) //move all items previous
pList->SetItemText(i, n-1, pList->GetItemText(i, n));
}
pList->DeleteColumn(nHeadCount-1); //delete last column
}