protected void AddGroupToSequence(TabGroupSequence tgs, TabGroupLeaf sourceLeaf, bool before) { // Remember original auto compact mode bool autoCompact = _tabbedGroups.AutoCompact; // Turn mode off as it interferes with reorganisation _tabbedGroups.AutoCompact = false; // Find our index into parent collection int pos = tgs.IndexOf(this); TabGroupLeaf newGroup = null; // New group inserted before existing one? if (before) newGroup = tgs.InsertNewLeaf(pos); else { // No, are we at the end of the collection? if (pos == (tgs.Count - 1)) newGroup = tgs.AddNewLeaf(); else newGroup = tgs.InsertNewLeaf(pos + 1); } // Get tab control for source leaf Controls.TabControl tc = sourceLeaf.GroupControl as Controls.TabControl; TabPage tp = tc.SelectedTab; // Remove page from ourself tc.TabPages.Remove(tp); // Add into the new leaf newGroup.TabPages.Add(tp); // Reset compacting mode as we have updated the structure _tabbedGroups.AutoCompact = autoCompact; // Do we need to compact? if (_tabbedGroups.AutoCompact) _tabbedGroups.Compact(); }