This is a migrated thread and some comments may be shown as answers.

Remove a splitpanel

2 Answers 415 Views
SplitContainer
This is a migrated thread and some comments may be shown as answers.
Abbas
Top achievements
Rank 1
Abbas asked on 03 Sep 2012, 10:11 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Julian Benkov
Telerik team
answered on 06 Sep 2012, 08:59 AM
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 >>
0
Abbas
Top achievements
Rank 1
answered on 07 Sep 2012, 10:54 AM
Hello Julian,
Thanks for your good supporting,
It was a good and useful example.

Best regards.
AM
Tags
SplitContainer
Asked by
Abbas
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Abbas
Top achievements
Rank 1
Share this question
or