Docking Manager - replace docked control

Hi, I have docked a control using the following code below however I would then like to replace this docked control with another control.

public void DockControl(Control c, Control parent, string name, int size, DockingStyle dockingStyle)
{
m_dockingManager.BeginInit();
m_dockingManager.DockControl(c, parent, dockingStyle, size);
m_dockingManager.SetDockLabel(c, name);
m_dockingManager.SetDockAbility(c, DockAbility.None);
m_dockingManager.EndInit();
}

My attemp to replace the control was to loop through the controls array and replace it however there is only a getter not a setter method...

public void ReplaceDockControl(Control c, Control replace)
{
int index = -1;
for (int i = 0; i < m_dockingManager.ControlsArray.Length; i++)
{
if (m_dockingManager.ControlsArray[i] == c)
{
index = i;
break;
}
}

if (index > -1)
{
m_dockingManager.ControlsArray[index] = replace;
}
}

Would be very greatful for any information.

1 Reply

MJ Mano J Syncfusion Team October 27, 2009 10:00 AM UTC

Hi David,

You can't replace a control unless you disable docking for the control.

You have to do the following in your code (ReplaceControl method) to achieve your requirement.

if (index > -1)
{
Control ctrl = dockingManager.ControlsArray[index];
// Get the properties from the controls
Control parent = ctrl.Parent.Parent;
Size size = dockingManager.GetControlSize(ctrl);
DockingStyle style = dockingManager.GetDockStyle(ctrl);
// Disable docking for the control.
dockingManager.SetEnableDocking(ctrl, false);
// dispose the control
ctrl.Dispose();
// replace with new control
DockControl(replace, parent, replace.Name, size.Width, style);
}

Thanks for using Syncfusion products.

Best Regards,
Mano

Loader.
Up arrow icon