dotnet windows forms designtime:
I am creating my own UITypeEditor for a class EAFDataBindingsCollection.
The type editor returns UITypeEditorEditStyle.Modal for GetEditStyle()
When I invoke the type editor at design time by clicking on the ... button
for a property of type EAFDataBindingsCollection, then the EditValue()
function is called, but I am having problems downcasting the "value"
argument. In the code below, the
value is EAFDataBindingsCollection
test returns false, yet the message box shows that "value" actually has this
type!
This is really confusing...
Does anyone know why?
TIA
Hugh Robinson
Here's the code from my UITypeEditor class:
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider,
object value) {
IWindowsFormsEditorService edSvc =
(IWindowsFormsEditorService)
provider.GetService(typeof(IWindowsFormsEditorService));
if (value is EAFDataBindingsCollection) {
// I never get here - even when value *is* of this type!
EAFDataBindingsCollection coll = (EAFDataBindingsCollection)
value;
// show the form to edit the collection
FormEAFDataBindingsCollectionEditor form =
new FormEAFDataBindingsCollectionEditor(coll);
if (DialogResult.OK == edSvc.ShowDialog(form)) {
// return the updated collection;
return form.EAFDataBindingsCollection;
}
} else {
if (value == null) {
MessageBox.Show("Value is null");
} else {
// This is where I actually end up
MessageBox.Show("Value has type " + value.GetType().ToString());
}
}
// return the value unchanged
return value;
}
}