CTabCtrl, enabling and disabling tabs

1.4k views Asked by At

Using Visual C++ MFC.

I have a dialog page, which contains a tab control object. I've created my own tab control class derived from CTabCtrl, where I created all my tab pages contained in an array, like so:

tabArray[0] = new TabPage;
tabArray[1] = new TabPage;

tabArray[0]->Create(DIALOG, this);
tabArray[1]->Create(DIALOG, this);

In my initial dialog page, I have a bunch of checkboxes. Depending on the state of these checkboxes, I add/remove the tab pages (but not the underlying TabPage classes!).

This is done like so. I keep track of which tabs are enabled/disabled in m_fTabEnabled. The state of the tab is toggled with the checkbox. This is used to determine which tab needs to be inserted.

m_fTabEnabled[iTab] = !m_fTabEnabled[iTab];

DeleteAllItems();

for(int i = 0; i < NUMOFTABS; ++i)
{
    if(m_fTabEnabled[i]) InsertItem(i, m_sTabNames[i]);
}

Using this method, I have an issue that if I have three tabs enabled, and I remove the second tab, that the dialog containing the data from the second tab is displayed on the third tab. For example:

tab 1, label 1, contains: 1
tab 2, label 2, contains: 2
tab 3, label 3, contains: 3

remove tab 2, tab 3 is shifted to tab 2

tab 1, label 1, contains: 1
tab 2, label 3, contains: 2
tab 3 hidden.

This causes a problem when I'm retrieving data from the tabs, because what I filled in tab three is lost to the data that used to be in tab two.

Does anybody have any suggestions on ways to manage this?

0

There are 0 answers