+ // don't stay with invalid m_key_current or we will crash in the next call
+ // to OnChar()
+ bool changeKeyCurrent = FALSE;
+ wxGenericTreeItem *itemKey = m_key_current;
+ while ( itemKey && !changeKeyCurrent )
+ {
+ if ( itemKey == item )
+ {
+ // m_key_current is a descendant of the item being deleted
+ changeKeyCurrent = TRUE;
+ }
+ else
+ {
+ itemKey = itemKey->GetParent();
+ }
+ }
+
+ wxGenericTreeItem *parent = item->GetParent();