I have created a control with controlcollection. When I add items from the property window at design time. It added perfectly. Also when I open it back. Added items shows me. But, When I close the form then open it again the items was removed.
Now I have added two Items in the collection. The items was looking perfectly.
But, When I open the Form.Desigern.cs
file the following line is missing.
this.xWizardControl.Window.Controls.Add(this.xWizardPage1);
this.xWizardControl.Window.Controls.Add(this.xWizardPage2);
The code is looks like this.
public class XWizardPageWindow : DevExpress.XtraEditors.XtraUserControl, ISupportInitialize
{
private XWizardPageCollection _pages;
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public XWizardPageCollection Pages
{
get { return _pages; }
set { _pages = value; }
}
public XWizardPageWindow()
{
}
#region Override Methods
protected override ControlCollection CreateControlsInstance()
{
if (_pages == null)
_pages = new XWizardPageCollection(this);
return _pages;
}
#endregion
#region ISupportInitialize Members
public void BeginInit()
{
//DO NOTHING
}
public void EndInit()
{
//DO NOTHING
}
#endregion
}
ControlCollection Class
public class XWizardPageCollection : System.Windows.Forms.Control.ControlCollection
{
public delegate void XWizardPageEventHandler(object sender, XWizardPageEventArgs e);
List<XWizardPage> _pages = new List<XWizardPage>();
#region Constructor
public XWizardPageCollection(System.Windows.Forms.Control owner): base(owner)
{}
#endregion
#region Override Methods
public override void Add(System.Windows.Forms.Control value)
{
base.Add(value);
value.Dock = System.Windows.Forms.DockStyle.Fill;
((XWizardPage)value).BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
}
#endregion
#region Destructor
~XWizardPageCollection()
{
GC.SuppressFinalize(this);
}
#endregion
}