How to delete values and header from ListCtrl
-
Hi How to delete all column headings and values from CListCtrl. I am doing in this way. int nColumnCount = m_ListCtrl.GetHeaderCtrl()->GetItemCount(); // Delete all of the columns. m_ListCtrl.DeleteAllItems(); for (int i=0;i < nColumnCount;i++) { m_ListCtrl.DeleteColumn(i); } Is it correct or not. when i again displaying values in this listcontrol it is not deleting column names but deleting values. what should i do. Thanks in advance.
-
Hi How to delete all column headings and values from CListCtrl. I am doing in this way. int nColumnCount = m_ListCtrl.GetHeaderCtrl()->GetItemCount(); // Delete all of the columns. m_ListCtrl.DeleteAllItems(); for (int i=0;i < nColumnCount;i++) { m_ListCtrl.DeleteColumn(i); } Is it correct or not. when i again displaying values in this listcontrol it is not deleting column names but deleting values. what should i do. Thanks in advance.
Try :
int nColumnCount = m_ListCtrl.GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
m_ListCtrl.DeleteAllItems();
for (int i=0;i < nColumnCount;i++)
{
m_ListCtrl.DeleteColumn( 0 );
}When you call
DeleteColumn
the header control is reindexing the columns everytime so always delete index 0 and you'll be ok. Gavin Taylor w: http://www.gavspace.com -
Hi How to delete all column headings and values from CListCtrl. I am doing in this way. int nColumnCount = m_ListCtrl.GetHeaderCtrl()->GetItemCount(); // Delete all of the columns. m_ListCtrl.DeleteAllItems(); for (int i=0;i < nColumnCount;i++) { m_ListCtrl.DeleteColumn(i); } Is it correct or not. when i again displaying values in this listcontrol it is not deleting column names but deleting values. what should i do. Thanks in advance.
int nColumnCount = m_ListCtrl.GetHeaderCtrl()->GetItemCount(); // Delete all of the columns. m_ListCtrl.DeleteAllItems(); for (int i=0;i < nColumnCount;i++) { m_ListCtrl.DeleteColumn(0); // always delete first column } You delete all items with m_ListCtrl.DeleteAllItems() and only first column.