Task is : select MyIntrerface Property for control in property grid from all components that implement MyInterface.
Descibe code:
Expand|Select|Wrap|Line Numbers
- interface MyInterface {}
- public class ControlClass : UserControl
- {
- MyInterface MyInterfaceProvider {get; set;}
- }
- public class ComponentClass : Component, MyInterface{}
- public class MainForm:Form
- {
- ControlClass _myControl;
- ComponentClass _myComponent;
- [...]
- }
Expand|Select|Wrap|Line Numbers
- public class InterfaceTypeConverter: TypeConverter{
- public override
- StandardValuesCollection GetStandardValues(
- ITypeDescriptorContext context){
- [...checks]
- // try to obtain ParentForm for getting _myComponent;
- ComponentParentForm = (context.Instance() as _myControl).ParentForm;
- MainForm MF = ComponentParentForm as MainForm;
- [...]
- }
- [...]
- }
MF == null
but
_myComponent.ParentForm is MainForm
but
ComponentParentForm is Form
!! ComponentParentForm is not MainForm !!
ComponentParentForm.Name == "MainForm"
How i can get ComponentParentForm with MainForm type ?