Remove a splitpanel

3 posts, 1 answers
  1. Abbas
    Abbas avatar
    2 posts
    Member since:
    Sep 2012

    Posted 03 Sep 2012 Link to this post

    Hi,
    How can I remove an added splitpanel from the splitcontainer, I know that collapsing a split panel doesn't remove it but I want to dispose the desired split panel like closing a form,In my program I add a container inside a new splitpanel and after manipulating and saving its  data I want to close and dispose it to free memory.
    Thanks

    I Solved my problem
    Thanks
    radSpContMain.SplitPanels[2].Dispose();
  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 06 Sep 2012 Link to this post

    Hello Abbas,

    Thank you for writing.

    You can use the RemoveAt method of the SplitPanels collection before Disposing, in order to achieve this functionality. Here is a example:
    using Telerik.WinControls.UI;
     
    namespace Lab.Dock
    {
        public partial class SplitMovePanelsForm : MainForm
        {
            public SplitMovePanelsForm()
            {
                InitializeComponent();
            }
     
            protected override void OnButton1Click()
            {
                MovePanel(1, 0);
            }
     
            protected override void OnButton2Click()
            {
                ClosePanel(1);
            }
     
            private void MovePanel(int oldIndex, int newIndex)
            {
                if (oldIndex < 0 || oldIndex >= this.radSplitContainer1.SplitPanels.Count || newIndex < 0 || newIndex >= this.radSplitContainer1.SplitPanels.Count)
                {
                    return;
                }
     
                SplitPanel splitPanel = this.radSplitContainer1.SplitPanels[oldIndex];
                this.radSplitContainer1.SplitPanels.RemoveAt(oldIndex);
                this.radSplitContainer1.SplitPanels.Insert(newIndex, splitPanel);
            }
     
            private void ClosePanel(int index)
            {
                if (index < 0 || index >= this.radSplitContainer1.SplitPanels.Count)
                {
                    return;
                }
     
                SplitPanel splitPanel = this.radSplitContainer1.SplitPanels[index];
                this.radSplitContainer1.SplitPanels.RemoveAt(index);
                splitPanel.Dispose();
            }
        }
    }

    Feel free to ask if you have any additional questions. 

    All the best,
    Julian Benkov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Abbas
    Abbas avatar
    2 posts
    Member since:
    Sep 2012

    Posted 07 Sep 2012 Link to this post

    Hello Julian,
    Thanks for your good supporting,
    It was a good and useful example.

    Best regards.
    AM
Back to Top