context.Instance().ParentForm has wrong type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Linkelf
    New Member
    • Oct 2009
    • 2

    context.Instance().ParentForm has wrong type

    Hi all! I have a form with controls and non-visual components. Some of them implements interface MyInterface and some have a MyInterface Property.
    Task is : select MyIntrerface Property for control in property grid from all components that implement MyInterface.

    Descibe code:

    Code:
    interface MyInterface {}
    
    public class ControlClass : UserControl
    {
      MyInterface MyInterfaceProvider {get; set;}
    }
    
    public class ComponentClass : Component, MyInterface{}
    
    public  class MainForm:Form
    {
     ControlClass _myControl;
     ComponentClass _myComponent;
     [...]
    }
    I wrote a typeconverter to perform string <=> MyInterface types conversation:

    Code:
    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;
      [...]
    }
     [...]
    }
    I have:

    MF == null

    but

    _myComponent.Pa rentForm is MainForm

    but

    ComponentParent Form is Form

    !! ComponentParent Form is not MainForm !!

    ComponentParent Form.Name == "MainForm"

    How i can get ComponentParent Form with MainForm type ?
  • Linkelf
    New Member
    • Oct 2009
    • 2

    #2
    Problem Solved !
    I cant and dont need convert ParentForm into MainForm type. All components i needed place in ComponentParent Form.Container. Components

    Comment

    Working...