Click here to Skip to main content
12,623,511 members (32,127 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: MFC
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...

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

Any suggestions?
Posted 10-Jun-12 18:09pm
DrBones692.2K
Updated 10-Jun-12 18:43pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
for(int i = 0; i < headCount; i++)
{
    m_ListCtrl.GetHeaderCtrl()->DeleteItem(0); // always delete column 0 only
}
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You need to set or unset the LVS_NOCOLUMNHEADER style in your list control as described here[^].
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 13 Jun 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100