Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm using a CTabCtrl with a CListCtrl inside the tab control, I need to know how to remove the column headings when I switch tabs. I've tried CListCtrl::DeleteColumn() and it does not seem to have an effect. I have also tried...

C++
int headCount = m_ListCtrl.GetHeaderCtrl()->GetItemCount();

for(int i = 0; i < headCount; i++)
{
    m_ListCtrl.GetHeaderCtrl()->DeleteItem(i);
}


Any suggestions?
Posted
Updated 10-Jun-12 17:43pm
v2

Your above code would fail to delete all the columns, half would always remain:

Say you had 3 columns

Columns 0, 1 and 2

you delete column 0, you now have columns 0, 1 as the remaining columns get promoted.
you delete column 1, you now have column 0 only
you attempt to delete column 2, but the call fails as there in no column 2
C++

C#
for(int i = 0; i < headCount; i++)
{
    m_ListCtrl.GetHeaderCtrl()->DeleteItem(0); // always delete column 0 only
}
 
Share this answer
 
Comments
DrBones69 13-Jun-12 21:16pm    
Thank you Roger, this is exactly what I have found out. I didn't realize until late last night that the column header indexing works like this. I have solved this issue with some functions.

Thanks,

DrB
You need to set or unset the LVS_NOCOLUMNHEADER style in your list control as described here[^].
 
Share this answer
 
Comments
DrBones69 12-Jun-12 21:45pm    
Thanks Richard, but I'm trying to replace the headers with new ones when selecting a new tab. When selecting a new tab, if I add a new column header it inserts into the existing headers.
Richard MacCutchan 13-Jun-12 3:45am    
I think you may need to use the SetItem() function, rather than deleting as above. Also your delete loop will only delete some of the items in your code sample, since you are deleting from zero instead of from the end working back.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900