Problem finding components on designer for use in TypeConverter 
Author Message
 Problem finding components on designer for use in TypeConverter

Bit confused here.
What about
public property CompA as Component1
That will give a drop down of all Component1's on current form...
Once selected, the property will contain a reference to the control so it
does not matter if the container has been setup or not..
(Through I suppose, you could trigger something of ParentChanged if you
really wanted to)


Quote:
> I want to be able to set the property of my customised
> datagrid to a
> component residing on the designer. I want to do this
> using the
> designer only. I've got so far:

> I've  created a class ('MyGrid') that inherits from the
> datagrid. I've
> added  a  property  ('CompA')  to  MyGrid  that  returns
> a class that
> implements IComponent ('Component1').

> I  want  to  be able to use the designer of MS Visual
> Studio to select
> any  components  of  type  'Component1'  that  I  have
> placed  in the
> designer.  eg  If  I  place  an  instance of MyGrid and an
> instance of
> Component1  on the designer of a form 'MyForm', then - in
> the property
> browser of MyGrid -
> I want to be able to select Component1 in a dropdown.

> The functionality is analogous to the way in which you can
> select any
> dataset components on the designer from the datasource
> property of the
> datagrid.

> Using   a   TypeConverter  (Component1Converter) I've got
> the Property
> browser dropdown working for Property 'CompA' of MyGrid,
> so that I can
> select any Component1 components that exist on the
> designer.

> The   problem   I've  got  is  that when the 'MyForm' is
> opened in the
> designer
> and   the  converter  attempts  to  find  and  return  the
> appropriate
> component  on  the  designer  (based  off  the string in
> the property
> browser that was previously selected)   the  context fed
> in by the
> ConvertFrom function has  -  at
> that  time  -  not initialised. I
> need the context in order to return the component . How do
> I get
> around this? (example code would help!)

> Thanks in advance,

> Adam

> ' Code for TypeConverter
> Imports System.ComponentModel

> Public Class Component1Converter
>     Inherits TypeConverter

>     Public Overloads Overrides Function ConvertFrom(ByVal
> context As System.ComponentModel.ITypeDescriptorContext, _
>     ByVal culture As System.Globalization.CultureInfo,
> ByVal value As Object) As Object
>         Dim obj As Component1
>         If context Is Nothing = False Then
>             Dim comp As IComponent
>             For Each comp In context.Container.Components
>                 If comp.Site.Name = value Then
>                     obj = CType(comp, Component1)
>                     Exit For
>                 End If
>             Next
>             Return obj
>         Else
>             Return Nothing
>             ' I don't really want this to return nothing.
> I really want to re-run this function when the
>             'context exists so that I can pick up the
> component that resides in the context
>         End If
>     End Function

>     Public Overloads Overrides Function CanConvertFrom
> (ByVal context As
> System.ComponentModel.ITypeDescriptorContext, _
>     ByVal sourceType As System.Type) As Boolean
>         If sourceType Is GetType(String) Then
>             Return True
>         Else : Return False
>         End If
>     End Function

>     Public Overloads Overrides Function CanConvertTo(ByVal
> context As System.ComponentModel.ITypeDescriptorContext, _
>     ByVal destinationType As System.Type) As Boolean
>         If destinationType Is GetType(String) And context
> Is Nothing = False Then
>             Return True
>         Else : Return False
>         End If
>     End Function

>     Public Overloads Overrides Function ConvertTo(ByVal
> context As System.ComponentModel.ITypeDescriptorContext, _
>     ByVal culture As System.Globalization.CultureInfo,
> ByVal value As Object, ByVal destinationType As
> System.Type) _
>     As Object
>         Dim str As String, obj As Component1
>         If value Is Nothing Then
>             str = ""
>             Return str
>         Else
>             obj = CType(value, Component1)
>             str = obj.Site.Name
>             Return str
>         End If
>     End Function

>     Public Overloads Overrides Function
> GetStandardValuesExclusive(ByVal context As _
>     System.ComponentModel.ITypeDescriptorContext) As
> Boolean
>         Return False
>     End Function

>     Public Overloads Overrides Function
> GetStandardValuesSupported(ByVal context As _
>     System.ComponentModel.ITypeDescriptorContext) As
> Boolean
>         Return True
>     End Function

>     Public Overloads Overrides Function GetStandardValues
> (ByVal context As _
>     System.ComponentModel.ITypeDescriptorContext) As
> System.ComponentModel.TypeConverter.StandardValuesCollectio
> n
>         Dim list As ArrayList = New ArrayList()
>         Dim comp As IComponent, comp1 As Component1
>         For Each comp In context.Container.Components
>             If TypeOf (comp) Is Component1 Then
>                 list.Add(CType(comp, Component1))
>             End If
>         Next
>         Dim coll As New
> System.ComponentModel.TypeConverter.StandardValuesCollectio
> n(list)
>         Return coll
>     End Function
> End Class

> 'Code for MyGrid
> Imports System.Web.UI.WebControls
> Imports Comp

> Public Class MyGrid
>     Inherits datagrid
>     Dim objComp As Component1

>     <ComponentModel.TypeConverter(GetType
> (Component1Converter))> Public Property compA() As
> Component1
>         Get
>             Return objComp
>         End Get
>         Set(ByVal Value As Component1)
>             objComp = Value
>         End Set
>     End Property
> End Class

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.*-*-*.com/ ).
Version: 6.0.381 / Virus Database: 214 - Release Date: 02/08/2002


Sun, 30 Jan 2005 06:53:06 GMT  
 Problem finding components on designer for use in TypeConverter
The problem I've got is that CompA is not persisted, so when I save or
build the project, the reference is lost. I was assuming (maybe
wrongly) that, as I have the component on the designer, then the
component is persisted somwhere and that I could then recreate the
reference using a typeconverter.

Thinking about it, though, it seems best that I persist CompA
completely myself(using the typeconverter), rather than trying to
recreate a reference.

I'll go that route.....

Thanks.

Quote:

> Bit confused here.
> What about
> public property CompA as Component1
> That will give a drop down of all Component1's on current form...
> Once selected, the property will contain a reference to the control so it
> does not matter if the container has been setup or not..
> (Through I suppose, you could trigger something of ParentChanged if you
> really wanted to)



> > I want to be able to set the property of my customised
> > datagrid to a
> > component residing on the designer. I want to do this
> > using the
> > designer only. I've got so far:

> > I've  created a class ('MyGrid') that inherits from the
> > datagrid. I've
> > added  a  property  ('CompA')  to  MyGrid  that  returns
> > a class that
> > implements IComponent ('Component1').

> > I  want  to  be able to use the designer of MS Visual
> > Studio to select
> > any  components  of  type  'Component1'  that  I  have
> > placed  in the
> > designer.  eg  If  I  place  an  instance of MyGrid and an
> > instance of
> > Component1  on the designer of a form 'MyForm', then - in
> > the property
> > browser of MyGrid -
> > I want to be able to select Component1 in a dropdown.

> > The functionality is analogous to the way in which you can
> > select any
> > dataset components on the designer from the datasource
> > property of the
> > datagrid.

> > Using   a   TypeConverter  (Component1Converter) I've got
> > the Property
> > browser dropdown working for Property 'CompA' of MyGrid,
> > so that I can
> > select any Component1 components that exist on the
> > designer.

> > The   problem   I've  got  is  that when the 'MyForm' is
> > opened in the
> > designer
> > and   the  converter  attempts  to  find  and  return  the
> > appropriate
> > component  on  the  designer  (based  off  the string in
> > the property
> > browser that was previously selected)   the  context fed
> > in by the
> > ConvertFrom function has  -  at
> > that  time  -  not initialised. I
> > need the context in order to return the component . How do
> > I get
> > around this? (example code would help!)

> > Thanks in advance,

> > Adam

> > ' Code for TypeConverter
> > Imports System.ComponentModel

> > Public Class Component1Converter
> >     Inherits TypeConverter

> >     Public Overloads Overrides Function ConvertFrom(ByVal
> > context As System.ComponentModel.ITypeDescriptorContext, _
> >     ByVal culture As System.Globalization.CultureInfo,
> > ByVal value As Object) As Object
> >         Dim obj As Component1
> >         If context Is Nothing = False Then
> >             Dim comp As IComponent
> >             For Each comp In context.Container.Components
> >                 If comp.Site.Name = value Then
> >                     obj = CType(comp, Component1)
> >                     Exit For
> >                 End If
> >             Next
> >             Return obj
> >         Else
> >             Return Nothing
> >             ' I don't really want this to return nothing.
> > I really want to re-run this function when the
> >             'context exists so that I can pick up the
> > component that resides in the context
> >         End If
> >     End Function

> >     Public Overloads Overrides Function CanConvertFrom
> > (ByVal context As
> > System.ComponentModel.ITypeDescriptorContext, _
> >     ByVal sourceType As System.Type) As Boolean
> >         If sourceType Is GetType(String) Then
> >             Return True
> >         Else : Return False
> >         End If
> >     End Function

> >     Public Overloads Overrides Function CanConvertTo(ByVal
> > context As System.ComponentModel.ITypeDescriptorContext, _
> >     ByVal destinationType As System.Type) As Boolean
> >         If destinationType Is GetType(String) And context
> > Is Nothing = False Then
> >             Return True
> >         Else : Return False
> >         End If
> >     End Function

> >     Public Overloads Overrides Function ConvertTo(ByVal
> > context As System.ComponentModel.ITypeDescriptorContext, _
> >     ByVal culture As System.Globalization.CultureInfo,
> > ByVal value As Object, ByVal destinationType As
> > System.Type) _
> >     As Object
> >         Dim str As String, obj As Component1
> >         If value Is Nothing Then
> >             str = ""
> >             Return str
> >         Else
> >             obj = CType(value, Component1)
> >             str = obj.Site.Name
> >             Return str
> >         End If
> >     End Function

> >     Public Overloads Overrides Function
> > GetStandardValuesExclusive(ByVal context As _
> >     System.ComponentModel.ITypeDescriptorContext) As
> > Boolean
> >         Return False
> >     End Function

> >     Public Overloads Overrides Function
> > GetStandardValuesSupported(ByVal context As _
> >     System.ComponentModel.ITypeDescriptorContext) As
> > Boolean
> >         Return True
> >     End Function

> >     Public Overloads Overrides Function GetStandardValues
> > (ByVal context As _
> >     System.ComponentModel.ITypeDescriptorContext) As
> > System.ComponentModel.TypeConverter.StandardValuesCollectio
> > n
> >         Dim list As ArrayList = New ArrayList()
> >         Dim comp As IComponent, comp1 As Component1
> >         For Each comp In context.Container.Components
> >             If TypeOf (comp) Is Component1 Then
> >                 list.Add(CType(comp, Component1))
> >             End If
> >         Next
> >         Dim coll As New
> > System.ComponentModel.TypeConverter.StandardValuesCollectio
> > n(list)
> >         Return coll
> >     End Function
> > End Class

> > 'Code for MyGrid
> > Imports System.Web.UI.WebControls
> > Imports Comp

> > Public Class MyGrid
> >     Inherits datagrid
> >     Dim objComp As Component1

> >     <ComponentModel.TypeConverter(GetType
> > (Component1Converter))> Public Property compA() As
> > Component1
> >         Get
> >             Return objComp
> >         End Get
> >         Set(ByVal Value As Component1)
> >             objComp = Value
> >         End Set
> >     End Property
> > End Class

> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.381 / Virus Database: 214 - Release Date: 02/08/2002



Mon, 31 Jan 2005 18:22:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem selecting records using ADO/Report designer component 6

2. Problem selecting records using ADO/Report designer component 6

3. Where can i find Baja, a Report Designer Component

4. SubReport Designer Component (ActiveX Designer)

5. Has someone used the Crystal Report Designer Component?

6. Sort order at runtime using CR Designer component?

7. Changing Groups Using Report Designer Component

8. Using Crystal Report Designer Component need to use mulitiple databases with same tables

9. Using Crystal 8.0 Report Designer Component

10. PDSMON.DLL problem with Report Designer Component

11. Report Designer Component - Install problems

12. Report Designer Component Problem With RecordSelectionFormula

 

 
Powered by phpBB® Forum Software