When I construct my control (which inherits DataGrid), I add specific rows and columns. This works great at design time. Unfortunately, at runtime I add my rows and columns in the same constructor, but then the DataGrid is serialized (after the constructor runs) adding more rows and columns.
After serialization is complete, I need to clear everything and re-initialize the rows and columns. Is there a protected method that I can override to know when the control is done serializing?
Of course, I'd prefer to not have to do the work in the constructor, throw it away, and do it again after (potential) serialization. Is there a preferred event that is the equivalent of "set yourself up now", so that it is called once whether I'm serialized or not?
The serialization i speak of comes from the InitializeComponent() method in the form's code-behind file.
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
...
}
It would have been perfect if InitializeComponent was a virtual method defined by Control, then i could just override it and then perform my processing after i call base:
protected override void InitializeComponent()
{
base.InitializeComponent();
InitializeMe();
}
But it's not an ancestor method, it's declared only in the code-behind file.
i notice that InitializeComponent calls SuspendLayout and ResumeLayout on various Controls. i thought it could override ResumeLayout, and perform my initialization then:
public override void ResumeLayout()
{
base.ResumeLayout();
InitializeMe();
}
But ResumeLayout is not virtual, so that's out.
Anymore ideas? i can't be the first person to create a custom control.