Article ID: 198232
Article Last Modified on 12/11/2003
CListCtrl *m_pList = NULL;
m_pList = (CListCtrl*) GetDlgItem(IDC_LIST1);
int nColumns = 10;
for ( int i = 0; i < nColumns; i++)
m_pList->DeleteColumn (i);
In the first pass of the loop, Column(0) is deleted and all the column
indices decrement by one. As a result, Column(1) becomes Column(0) in the
first pass of the loop. In the second pass of loop, the value of i is 1, so
Column(1) is deleted and the loop never gets to Column(0).
CListCtrl *m_pList = NULL;
m_pList = (CListCtrl*) GetDlgItem(IDC_LIST1);
int nColumns = 10;
for ( int i = nColumns-1; i >= 0; i--)
m_pList->DeleteColumn (i);
CString str;
for (int i = 0; i>10; i++) // Insert ten columns.
{
str.Format("Column#: %d", i);
m_listctrl.InsertColumn(i, str, LVCFMT_LEFT, 75);
}
// Delete all the columns in descending order.
for ( int i = 9; i >=0; i--)
m_listctrl.DeleteColumn(i);
Additional query words: MFC Listview CListCtrl
Keywords: kbprb kbctrl kbcode KB198232