Problem with CTreeCtrl::DeleteAllItems
-
I have a strange problem with CTreeCtrl::DeleteAllItems under VS2003: it seems impossible to insert a new tree item after having called this function. Let's try a simple example: - Create a new MFC dialog application, - Add a tree control in the dialog, - Associate a CTreeCtrl variable with it, - in the OnInitDialog, add the code:
c_Tree.InsertItem(_T("Item before")); c_Tree.DeleteAllItems(); c_Tree.InsertItem(_T("Item after"));
When executing the prg, the control remains empty. However, if I comment the call to DeleteAllItems, I see two items as expected. X| Has anybody already experimented this ? -
I have a strange problem with CTreeCtrl::DeleteAllItems under VS2003: it seems impossible to insert a new tree item after having called this function. Let's try a simple example: - Create a new MFC dialog application, - Add a tree control in the dialog, - Associate a CTreeCtrl variable with it, - in the OnInitDialog, add the code:
c_Tree.InsertItem(_T("Item before")); c_Tree.DeleteAllItems(); c_Tree.InsertItem(_T("Item after"));
When executing the prg, the control remains empty. However, if I comment the call to DeleteAllItems, I see two items as expected. X| Has anybody already experimented this ?Just a quess but try adding a
UpdateData(FALSE);
after the last InsertItem Arjan -
Just a quess but try adding a
UpdateData(FALSE);
after the last InsertItem ArjanI doesn't change anything because UpdateData usually validates DDX data and not DDX controls. However, insertions work perfectly as long as I do not use DeleteAllItems. As soon it is called, no further insertions are possible (ie. InsertItem returns a valid HTREEITEM handle, but the tree control client area remains empty, even if I force the control to redraw.) Looks like DeleteAllItems makes a real mess in the control! :confused:
-
I doesn't change anything because UpdateData usually validates DDX data and not DDX controls. However, insertions work perfectly as long as I do not use DeleteAllItems. As soon it is called, no further insertions are possible (ie. InsertItem returns a valid HTREEITEM handle, but the tree control client area remains empty, even if I force the control to redraw.) Looks like DeleteAllItems makes a real mess in the control! :confused:
You're right this is a bug! But you can workaround it.
m_cTree.InsertItem("Before"); m_cTree.SetRedraw(FALSE); m_cTree.DeleteAllItems(); m_cTree.InsertItem("after"); m_cTree.SetRedraw(TRUE);
or just set the tree's scroll property to true. Arjan -
You're right this is a bug! But you can workaround it.
m_cTree.InsertItem("Before"); m_cTree.SetRedraw(FALSE); m_cTree.DeleteAllItems(); m_cTree.InsertItem("after"); m_cTree.SetRedraw(TRUE);
or just set the tree's scroll property to true. Arjan -
You're right this is a bug! But you can workaround it.
m_cTree.InsertItem("Before"); m_cTree.SetRedraw(FALSE); m_cTree.DeleteAllItems(); m_cTree.InsertItem("after"); m_cTree.SetRedraw(TRUE);
or just set the tree's scroll property to true. Arjan