내 PropertyGrid의 탐색 가능한 속성에서 속성 중간 이름을 제외하려고합니다.ICustomTypeDescriptor 구현시 인수 예외가 throw됩니다.
내 Person 클래스의 ICustomTypeDescriptor 인터페이스를 사용할 때 내 응용 프로그램을 시작할 때이 예외가 발생합니다.
무엇이 잘못 되었나요?
System.ArgumentException: Can not bind to the property or column TestNamefür on the DataSource. Parametername: dataMember bei System.Windows.Forms.BindToObject.CheckBinding() bei System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase) bei System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)
public class Person : ICustomTypeDescriptor
{
public string TestName { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
return TypeDescriptor.GetAttributes(this, true);
}
string ICustomTypeDescriptor.GetClassName()
{
return TypeDescriptor.GetClassName(this, true);
}
string ICustomTypeDescriptor.GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
{
Debug.Print("GetProperties()");
Print("Attributes is {0}null", attributes == null ? "" : "not ");
PropertyDescriptorCollection origCol = TypeDescriptor.GetProperties(this, attributes, true);
bool wantBrowsable = attributes.Contains<Attribute>(new BrowsableAttribute(true));
Debug.Print("Wants Browsable: {0}", wantBrowsable);
List<PropertyDescriptor> newCol = new List<PropertyDescriptor>();
foreach (PropertyDescriptor pd in origCol)
{
System.Diagnostics.Debug.Print("Property Name: {0}", pd.Name);
if (pd.Name != "MiddleName")
{
System.Diagnostics.Debug.Print("Property {0} is included.", pd.Name);
newCol.Add(pd);
}
}
return new PropertyDescriptorCollection(newCol.ToArray());
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
return ((ICustomTypeDescriptor)this).GetProperties(null);
}
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
}
UPDATE + 해결책 :
속성 Browseable(false)
로 표시됩니다 바인딩 할 수 없습니다! 마크 Gravell에서 마지막 솔루션은 호흡처럼 일
Why Browsable attribute makes property not bindable?
: 그래서 이런 짓을!
=> 나는 이마를 사용한다면 => seable attribut에 대한 TestName 동일한 예외 :/ – Elisabeth
사람 클래스에서'ICustomTypeDescriptor' 구현을 제거하더라도? 정말 이상하게 보입니다 ... Person 클래스가 정확히 어떻게 게시 했습니까? – digEmAll
@Lisa : 내 편집을 확인하십시오.) – digEmAll