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;
}
}
「自定義屬性聲明」解決!謝謝。 –