I have build a Component based upon the DataGridView. This Component extends the DataGridView in several ways. I am using IPersistComponentSettings in order to save
I am using IPersistComponentSettings to persist Column Widths. So from the user's perspective all column width adjustments are persisted - much like the experience obtained when using MS Excel. This works well.
The problem I am experiencing is that all forms that use this Component fails to load. One of the methods required by the IPersistComponentSettings is the LoadComponentSettings(). In this method, I extract the persisted values for column widths and set the widths:
public virtual void LoadComponentSettings()
{
ColumnSettings[] columnSettings = Settings.Columns;
foreach (ColumnSettings settings in columnSettings)
{
DataGridViewColumn column = Columns[settings.Name];
column.Width = settings.Width;
}
}
The Problem:
In Visual Studio when I bring up the designer for forms that use this Component, an error page is displayed that says "Object reference not set to an instance of an object" and from the Call Stack, I am able to deduce that the problem is thatI use the following for the SettingsKey:
this.FindForm().Name + this.Name
The designer is crashing on this.FindForm().Name