Hi,
I'm trying to use the NDockManager in a specific way and I'm running into some difficulty. My requirements are that various User Defined Controls should be able to be added and removed from the NDockManager when a user clicks a button or selects a menu item. I have a code base that works for the most part except when I get the following error: "Unable to cast object of type 'Nevron.UI.WinForm.Docking.l1lIlll' to type 'Nevron.UI.WinForm.Docking.NDockingPanelHost'."
Could you please explain what exactly is the type: 'Nevron.UI.WinForm.Docking.l1lIlll' ? Why the funny string of | (bars), I (capital I's), and 1 (ones) ? What does this represent?
However, my main issue is that I cannot reliable find and remove a control (and its panel & panelHost) if a user has been moving and re-docking panelHosts. Perhaps I am using a bad approach. Any suggestions would be extremely welcome. Thanks!!
This is how I'm adding controls to the NDockManager:
private void AddControl(string text, string key, Control control, DockStyle dockStyle)
{
// === The control. This is a user defined control that we have written.
control.Tag = key;
control.Dock = DockStyle.Fill;
// === The panel.
NDockingPanel panel = new NDockingPanel();
panel.Key = key;
panel.Text = text;
panel.Dock = dockStyle;
panel.Closing += new PanelCancelEventHandler(_panel_Closing);
panel.Controls.Add(control);
// === The panel host.
NDockingPanelHost panelHost = new NDockingPanelHost();
panelHost.AddChild(panel);
// === The dock manager.
nDockManager1.RootContainer.RootZone.AddChild(panelHost, nDockManager1.RootContainer.RootZone.Children.Count);
}
Example of trying to remove a control from the dock manager:
private bool removeControlFromWhereEverItIs(string key)
{
Control controlToRemove = null;
NDockingPanel panelToRemove = null;
NDockingPanelHost panelHostToRemove = null;
bool foundTheControl = _removeControlFromWhereEverItIs(key, null, ref panelHostToRemove, ref panelToRemove, ref controlToRemove);
if (foundTheControl)
{
if (controlToRemove != null) // We have to remove the control OUTSIDE of the iterating over the panel.Controls collection.
panelToRemove.Controls.Remove(controlToRemove);
if (panelToRemove != null) // We need to remove its panel also.
panelHostToRemove.RemoveChild(panelToRemove);
if (panelHostToRemove != null) // We need to remove its panel also.
nDockManager1.RootContainer.RootZone.RemoveChild(panelHostToRemove);
}
return foundTheControl;
}
private bool _removeControlFromWhereEverItIs(string key, INDockZoneChild recursiveCanBeNullForTopLevel, ref NDockingPanelHost panelHostToRemove, ref NDockingPanel panelToRemove, ref Control controlToRemove)
{
bool foundTheControl = false;
if (recursiveCanBeNullForTopLevel == null)
{
foreach (INDockZoneChild ph in nDockManager1.RootContainer.RootZone.Children)
if (!foundTheControl)
foundTheControl = _removeControlFromWhateverZoneItsIn(key, ph, ref panelHostToRemove, ref panelToRemove, ref controlToRemove);
else
break;
}
else
{
NDockingPanelHost prototype = new NDockingPanelHost();
NDockingPanelHost panelHost = (NDockingPanelHost)recursiveCanBeNullForTopLevel; // <<--== ERROR OCCURS HERE: 'Nevron.UI.WinForm.Docking.l1lIlll' to type 'Nevron.UI.WinForm.Docking.NDockingPanelHost'
foreach (NDockingPanel panel in panelHost.Children)
{
foreach (Control control in panel.Controls)
{
if (control.Tag.ToString() == key)
{
controlToRemove = control;
panelToRemove = panel;
panelHostToRemove = panelHost;
foundTheControl = true;
break;
}
}
if (foundTheControl) break;
}
}
return foundTheControl;
}