Note that there are some explanatory texts on larger screens.

plurals
  1. POICustomTypeDescriptor databinding to textbox
    primarykey
    data
    text
    <p>I have a model that implements ICustomTypeDescriptor. This is because I want to be able to add custom properties ... that are not in the object and bind them to a textbox. The strange part is that the binding works great to a PropertyGrid but not to a textbox. </p> <p>This code works: </p> <pre><code>DynamicClass&lt;ExtensionModel&gt; binder = new DynamicClass&lt;ExtensionModel&gt;(ext); propertyGrid1.SelectedObject = binder; </code></pre> <p>but not his one: </p> <pre><code>var binder = new DynamicClass&lt;ExtensionModel&gt;(ext); _versionLabel.DataBindings.Add("Text", binder, "SelectedVersion", false, DataSourceUpdateMode.OnPropertyChanged); </code></pre> <p>In this case I get Object does not match target type. exception. If I put ext instead of binder in the binding it works fine.</p> <p>Is there a problem with the textbox binding capabilities?</p> <p>My code for DynamicClass is: </p> <pre><code>public class DynamicClass&lt;T&gt; : ICustomTypeDescriptor { private readonly T _object; public DynamicClass(T trackedObject) { _object = trackedObject; } // Collection to code add dynamic properties public KeyedCollection&lt;string, DynamicProperty&gt; Properties { get; private set; } // ICustomTypeDescriptor implementation AttributeCollection ICustomTypeDescriptor.GetAttributes() { return TypeDescriptor.GetAttributes(_object, true); } string ICustomTypeDescriptor.GetClassName() { return TypeDescriptor.GetClassName(_object, true); } string ICustomTypeDescriptor.GetComponentName() { return TypeDescriptor.GetComponentName(_object, true); } TypeConverter ICustomTypeDescriptor.GetConverter() { return TypeDescriptor.GetConverter(_object, true); } EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() { return TypeDescriptor.GetDefaultEvent(_object, true); } PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() { return TypeDescriptor.GetDefaultProperty(_object, true); } object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return TypeDescriptor.GetEditor(_object, editorBaseType, true); } EventDescriptorCollection ICustomTypeDescriptor.GetEvents() { return TypeDescriptor.GetEvents(_object, true); } EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) { return TypeDescriptor.GetEvents(_object, attributes, true); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { return TypeDescriptor.GetProperties(_object, true); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { return TypeDescriptor.GetProperties(_object, attributes, true); } object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) { return _object; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload