hi sebastian, that sample code is a good example showing how to create
editabledesignerregions, however some pieces of code are missing.
Specifically they forgot(or maybe its intentional) to include the lines of
code that add the controls in the templates(view1 and view2) into the
specified content region. The missing code in the CreateChildControls method
is :
if (CurrentView == 0)
{
if (View1 != null)
{
View1.InstantiateIn(tc);
}
}
else if (CurrentView == 1)
{
if (View2 != null)
{
View2.InstantiateIn(tc);
}
}
The complete code for the CreateChildControls method after the above
modification is :
// Create a simple table with a row of two clickable,
// readonly headers and a row with a single column, which
// is the 'container' to which we'll be adding controls.
protected override void CreateChildControls()
{
// Always start with a clean form
Controls.Clear();
// Create a table using the control's declarative properties
Table t = new Table();
t.CellSpacing = 1;
t.BorderStyle = BorderStyle;
t.Width = this.Width;
t.Height = this.Height;
// Create the header row
TableRow tr = new TableRow();
tr.HorizontalAlign = HorizontalAlign.Center;
tr.BackColor = Color.LightBlue;
// Create the first cell in the header row
TableCell tc = new TableCell();
tc.Text = "View1";
tc.Width = new Unit("50%");
tr.Cells.Add(tc);
// Create the second cell in the header row
tc = new TableCell();
tc.Text = "View 2";
tc.Width = new Unit("50%");
tr.Cells.Add(tc);
t.Rows.Add(tr);
// Create the second row for content
tr = new TableRow();
tr.HorizontalAlign = HorizontalAlign.Center;
// This cell represents our content 'container'
tc = new TableCell();
tc.ColumnSpan = 2;
if (CurrentView == 0)
{
if (View1 != null)
{
View1.InstantiateIn(tc);
}
}
else if (CurrentView == 1)
{
if (View2 != null)
{
View2.InstantiateIn(tc);
}
}
tr.Cells.Add(tc);
t.Rows.Add(tr);
// Add the finished table to the Controls collection
Controls.Add(t);
}
Have a good easter,
Alessandro Zifiglio.