我为我的属性网格定义了一个属性,它的值是创建者的集合。我定义CreatorsEditor类。在这个类中,我使用HumanRolesCode变量。如何在属性的属性中访问此变量以获取设置值。我想更改HumanRolesCode值。例如:[Editor(typeof(CreatorsEditor(HumanRolesCode = 10))]
我的代码是:
[Editor(typeof(CreatorsEditor), typeof(UITypeEditor))]
public string Creators { get; set; }
//-------------------------------------
public class CreatorsEditor : UITypeEditor
{
public static int HumanRolesCode;
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (svc != null)
{
CreatorFrm.HumanRoleCode = HumanRolesCode;
CreatorFrm Frm = new CreatorFrm();
if (svc.ShowDialog(Frm) == System.Windows.Forms.DialogResult.OK)
{
string HumanNames = "";
for (int i = 0; i < Frm.DgvCreator.Rows.Count; i++)
if (Boolean.Parse(Frm.DgvCreator[0, i].Value.ToString()) == true)
HumanNames += Frm.DgvCreator[2, i].Value.ToString() + " , ";
if (!string.IsNullOrEmpty(HumanNames))
HumanNames = HumanNames.Substring(0, HumanNames.Length - 3);
return HumanNames;
}
}
return value;
}
}