+ node->ChangeSubTreeCount(-itemsDeleted);
+
+ // Update selection by removing 'item' and its entire children tree from the selection.
+ if ( !m_selection.empty() )
+ {
+ // we can't call GetRowByItem() on 'item', as it's already deleted, so compute it from
+ // the parent ('node') and position in its list of children
+ int itemRow;
+ if ( itemPosInNode == 0 )
+ {
+ // 1st child, row number is that of the parent node + 1
+ itemRow = GetRowByItem(node->GetItem()) + 1;
+ }
+ else
+ {
+ // row number is that of the sibling above 'item' + its subtree if any + 1
+ const wxDataViewItem sibling = wxDataViewItem(node->GetChildren()[itemPosInNode - 1]);
+ const wxDataViewTreeNode *siblingNode = node->FindItemAsNode(sibling);
+
+ itemRow = GetRowByItem(sibling);
+ if ( siblingNode )
+ itemRow += siblingNode->GetSubTreeCount();
+ itemRow += 1;
+ }
+
+ wxDataViewSelection newsel(wxDataViewSelectionCmp);
+
+ for ( wxDataViewSelection::const_iterator i = m_selection.begin();
+ i != m_selection.end();
+ ++i )
+ {
+ const int s = *i;
+ if ( s < itemRow )
+ newsel.push_back(s);
+ else if ( s >= itemRow + itemsDeleted )
+ newsel.push_back(s - itemsDeleted);
+ // else: deleted item, remove from selection
+ }
+
+ m_selection = newsel;
+ }