public class MyGrid
{
public List<Column> Columns = new List<Column>();
public int DefaultColumnWidth
{
get
{
return _DefaultColWid;
}
set
{
if (value != _DefaultColWid)
{
_DefaultColWid = value;
List<Column> col = new List<Column>();
foreach (var item in Columns)
{
item.Width = value;
col.Add(item);
}
Columns = col;
}
}
}
private int _DefaultColWid = 10;
public void Test()
{
Columns.Add(new Column());
int x;
x = Columns[0].Width;
Console.WriteLine(x);
DefaultColumnWidth = 121;
x = Columns[0].Width;
Console.WriteLine(x);
DefaultColumnWidth = 45;
x = Columns[0].Width;
Console.WriteLine(x);
}
}
public class Column : MyGrid
{
private int width = -1;
public int Width
{
get
{
if (width >= 0)
return width;
else
return base.DefaultColumnWidth;
}
set
{
width = value;
}
}
}
This is what i have done but this is not the right approach .for implementing you scenario
you need implement a design pattern which is named as OBSERVER here is the link for it.
http://www.dofactory.com/Patterns/PatternObserver.aspx#_self1[
^]