Reputation: 43
I've taken over someone else's project and they have used Krypton Toolkit. When I change anything on the UI, (i.e., Add button, edit Text, add menu item), I get this exception error:
this.kryptonHeaderGroupMain.Controls.Add(this.kryptonHeaderGroupMain.Panel);
Cause an exception "ReadOnly controls collection"
..and it mucks up the Designer View.
What am I missing?
As some people recommended, I have tried it but still failed:
this.<kryptonControlsContainer>.Panel.Controls.Add(this.<otherControlName>);
Upvotes: 3
Views: 1236
Reputation: 19651
The Controls
property of the KryptonHeaderGroup
control is a custom Controls Collection (it's named KryptonReadOnlyControls
) which doesn't allow adding or removing child controls. The way KryptonHeaderGroup
was designed is that it has a Panel
which acts as the container for its child controls. What you need to do is as follows.
Before adding any controls, make sure you select the panel and not the KryptonHeaderGroup
itself. See the difference in these screenshots:
//kryptonHeaderGroup1.Controls.Add(new KryptonButton()); // Throws an exception.
kryptonHeaderGroup1.Panel.Controls.Add(new KryptonButton()); // Works fine.
Note: The same logic applies for other controls like KryptonGroupBox
, KryptonGroup
, and KryptonSplitContainer
.
Upvotes: 2