Вот "как пример" можно реализовать так. Уж извините за длинный код, но он компилируется

using System;
using System.ComponentModel;
using System.Windows.Forms;
public class MyForm :Form
{
PropertyGrid grid = new PropertyGrid();
Sample sample = new Sample();
public MyForm()
{
grid.Dock = DockStyle.Fill;
this.Controls.Add(grid);
grid.SelectedObject = sample;
sample.PropertyViewChanged += new Sample.SetTaskForObjectDeleagte(this.SetNewTask);
sample.A = 0;
}
private void SetNewTask(object obj,TaskTypeViewAttribute newAttr)
{
this.grid.BrowsableAttributes = new AttributeCollection(new Attribute[]{newAttr});
this.grid.Refresh();
}
public static void Main()
{
Application.Run(new MyForm());
}
}
public class Sample
{
public delegate void SetTaskForObjectDeleagte(object sender,TaskTypeViewAttribute newAttr);
public event SetTaskForObjectDeleagte PropertyViewChanged;
private int a = 0;
private int b = 0;
[TaskTypeView(1)]
public int A
{
get{return a;}
set{
this.a = value;
if (a == 0)
{
PropertyViewChanged(this,TaskTypeViewAttribute.FirstTask);
}
else
{
PropertyViewChanged(this,TaskTypeViewAttribute.NoneTask);
}
}
}
[TaskTypeView(2)]
public int B
{
get{return b;}
set{this.b = value;}
}
}
[AttributeUsage(AttributeTargets.All)]
public class TaskTypeViewAttribute:Attribute
{
private int taskType;
public static readonly TaskTypeViewAttribute FirstTask;
public static readonly TaskTypeViewAttribute SecondTask;
public static readonly TaskTypeViewAttribute NoneTask;
public int TaskType
{
get {return this.taskType;}
}
public TaskTypeViewAttribute():this(0)
{}
public TaskTypeViewAttribute(int taskType)
{
this.taskType = taskType;
}
public override bool Match(object obj)
{
if (this.taskType==0)
return true;
else if (obj is TaskTypeViewAttribute)
{
return (obj as TaskTypeViewAttribute).TaskType == TaskType;
}
else
return false;
}
static TaskTypeViewAttribute()
{
FirstTask = new TaskTypeViewAttribute(1);
SecondTask = new TaskTypeViewAttribute(2);
NoneTask = new TaskTypeViewAttribute(0);
}
}
Если ввести ненулевое значение A — то появится B
Я думаю — идея понятна.
А развить ее дальше — это дело техники.
данное сообщение получено с www.gotdotnet.ru
ссылка на оригинальное сообщение