I am developing MyDataGridView control with fixed columns and rows.
public partial class MyDataGridView
{
public MyDataGridView()
{
CreateColumns();
CreateRows();
}
}
When I add MyDataGridView onto a Form at design-time the designer is autogenerating more columns - exactly the same columns as created with CreateColumns() in the constructor above. Can I stop the designer from doing this?
private void CreateColumns(); // Creates columns of MyDataGridView.
Please add this code to a WindowsFormsApplication project, compile and drag MyDataGridView control from ToolBox on a Form1 then run the application. See how the Designer behaves and generates code (Form1.Designer.cs).
namespace WindowsFormsApplication1
{
public class MyDataGridView : System.Windows.Forms.DataGridView
{
public MyDataGridView()
{
CreateColumns();
CreateRows();
}
private void CreateColumns()
{
for (int day = 0; day < 7; day++)
{
this.Columns.Add(new DataGridViewTextBoxColumn());
}
}
private void CreateRows()
{
for (int n = 0; n < 6; n++)
{
this.Rows.Add(new DataGridViewRow());
}
}
}
}