4
我为我的properygrid定义了一个属性,它的值是创建者的集合。我定义了CreatorsEditor类。在这个类中,我使用HumanRolesCode变量。我怎样才能访问这个变量属性的属性设置值。我想要改变HumanRolesCode的值。例如:[编辑器(typeof运算(CreatorsEditor(HumanRolesCode = 10))]如何在c#中访问属性属性中的类变量?
我的代码是:
[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;
}
}
“自定义属性声明”解决!谢谢。 –