J
Jeronimo Bertran
Hi,
What is the correct way to sbuclass a datagrid that we want to use in the
designer that includes default columns?
I am trying to create a control that inherits from DataGrid and performs
some standard manipulation (such as creating default columns)....
public class MyGrid : System.Windows.Forms.DataGrid
I add columns either with the designer or on the constructor:
//
// dataGridTableStyle
//
this.dataGridTableStyle.DataGrid = this;
this.dataGridTableStyle.GridColumnStyles.AddRange(new
System.Windows.Forms.DataGridColumnStyle[] {this.dataGridNameColumn});
this.dataGridTableStyle.MappingName = "ArrayList";
//
// dataGridNameColumn
//
this.dataGridNameColumn.HeaderText = "Name";
this.dataGridNameColumn.MappingName = "Name";
Now, if I add my grid to the ToolBox and add it to a form, a new instance
of the GridTableSytle and and GridColumnStyle is created in the form. I
get an error because I now have 2 TableStyles with the same MappingName.
If I delete the TableStyle collection from the designer then it then works
ok and only the instance created on the class is used.
Thanks,
Jeronimo Bertran
What is the correct way to sbuclass a datagrid that we want to use in the
designer that includes default columns?
I am trying to create a control that inherits from DataGrid and performs
some standard manipulation (such as creating default columns)....
public class MyGrid : System.Windows.Forms.DataGrid
I add columns either with the designer or on the constructor:
//
// dataGridTableStyle
//
this.dataGridTableStyle.DataGrid = this;
this.dataGridTableStyle.GridColumnStyles.AddRange(new
System.Windows.Forms.DataGridColumnStyle[] {this.dataGridNameColumn});
this.dataGridTableStyle.MappingName = "ArrayList";
//
// dataGridNameColumn
//
this.dataGridNameColumn.HeaderText = "Name";
this.dataGridNameColumn.MappingName = "Name";
Now, if I add my grid to the ToolBox and add it to a form, a new instance
of the GridTableSytle and and GridColumnStyle is created in the form. I
get an error because I now have 2 TableStyles with the same MappingName.
If I delete the TableStyle collection from the designer then it then works
ok and only the instance created on the class is used.
Thanks,
Jeronimo Bertran