Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Insertitem() method in observable collection is duplicate allowed or not.
--- i have create tabsplitter control in wpf. The panel is collapse means it will collapse.
---i have added only bottom page.
---when panel is expand it will throw Exception in Argument outof range Exception.
i have use in below code
----------------------------------
C#
 protected override void InsertItem(int index, SplitterPage item)
        {
            base.InsertItem(index, item);//index 0 added item,index 1 add same item in it will throw Argument out of range Exception
            item.PageStorage = this;
            SelectedIndex = index;
        }
-----------------------------------
  internal void ExpandPanel(TabSplitterItem item, SplitterPagesCollection topItems, SplitterPagesCollection bottomItems)
        {
            SplitterPagesCollection bottomPages = item.BottomPages;

            if (bottomPages != null)
            {
                while (bottomPages.Count != 0)
                {
                    SplitterPage bottomPage = bottomPages[0];
                    bottomPage.ClearValue(SplitterPage.TabStripPlacementPropertyKey);

                    bottomPages.Remove(bottomPage);
                    topItems.Remove(bottomPage);

                    if (bottomPage.IsSelected || bottomPage.IsSelectedPage)
                    {
                        topItems.Remove(bottomPage);
                        var topPage = topItems[0];
                        topItems.Remove(topPage);
                        SplitterPage.SetTabStripPlacement(bottomPage,Dock.Bottom);
                        SplitterPage.SetTabStripPlacement(topPage, Dock.Top);
                        UpdateSkinToContent(topPage);
                        UpdateSkinToContent(bottomPage);
                        bottomItems.Add(topPage);
                        topItems.Add(bottomPage);
                    }
                    else
                    {
                        UpdateSkinToContent(bottomPage);
                        bottomItems.Add(bottomPage);
                    }
                }
            }
        }
Posted
Updated 3-Sep-15 2:03am
v2
Comments
CHill60 3-Sep-15 8:07am    
I doubt that this has any thing to do with duplicates. Try debugging and checking the value of variables ... particularly bottomPage when you try to add it.

1 solution

I think you misunderstand indexes in this case. You add one page (bottom or top, not relevant). That is your index 0. When you do this:

C#
topItems.Remove(bottomPage);

You're removing the element from topItems...if that was the only element, your next reference
C#
var topPage = topItems[0];

will be out of range.

Put a breakpoint into the method and go step by step.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900