private void GroupSelectedItems() { var sbl = BlockList.GetSelectedBlockList(); int count = sbl.listBlocks.SelectedItems.Count; if (count == 0) { System.Media.SystemSounds.Beep.Play(); return; } string prompt; if (count == 1) { prompt = "Group Selected Block?"; } else if (count == sbl.listBlocks.Items.Count) { prompt = "Group All Blocks?"; } else { prompt = string.Format("Group {0} Selected Blocks?", sbl.listBlocks.SelectedItems.Count); } if (MessageBox.Show(prompt, "Block Editor", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { inSelectionChanged = true; IBlockGroup group = BlockManager.NewBlockGroup(); List <IBlock> blockList = new List <IBlock>(); blockList.AddRange(sbl.Blocks); IBlock[] selectedBlocks = sbl.AdjacentSelectedBlocks; int index = blockList.IndexOf(selectedBlocks[0]); blockList.Insert(index, group); foreach (IBlock block in selectedBlocks) { group.Add(block); blockList.Remove(block); } foreach (IBlock block in blockList) { block.NewBlockItem(); } sbl.Clear(); sbl.Add(blockList.ToArray()); sbl.listBlocks.SelectedItem = group.BlockItem; listCode.UnselectAll(); if (sbl.ParentGroup != null) { sbl.ParentGroup.Blocks = sbl.Blocks; } Edited = true; btnDelete.IsEnabled = btnCut.IsEnabled = btnCopy.IsEnabled = btnGroup.IsEnabled = btnUngroup.IsEnabled = true; inSelectionChanged = false; } }