Results 1 to 6 of 6

Thread: How to have a content collection on a user control that has a prop refs another ctl

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,373

    How to have a content collection on a user control that has a prop refs another ctl

    If I create a property on a user control to reference another control e.g:
    VB.Net Code:
    1. Public Property BindingSource As BindingSource
    I can select a BindingSource control that has been inserted on the form without issues.

    What I am trying to do is allow multiple to be added to a collection such that:
    VB.Net Code:
    1. Imports System.ComponentModel
    2.  
    3. Public Class UserControlTest
    4.     <Serializable>
    5.     <DebuggerDisplay("{" & NameOf(MiscDataProvider.ToString) & "}")>
    6.     Public Class MiscDataProvider
    7.         Public Property BindingSource As BindingSource
    8.         Public Overrides Function ToString() As String
    9.             Return If(TryCast(BindingSource?.DataSource, Type)?.Name, "Unknown")
    10.         End Function
    11.     End Class
    12.  
    13.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
    14.     Public ReadOnly Property MiscDataProviders As New List(Of MiscDataProvider)
    15.  
    16. End Class

    The issue I have is it complains that the BindingSource is not serializable.
    How can I make this work? - I need it to be a reference to the form's one as it does with the direct property in the user control.

    Thanks in advance,
    Kris

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,510

    Re: How to have a content collection on a user control that has a prop refs another c

    While this doesn't answer your question I have a suggestion:

    Code:
                If DataSourceType Is Nothing Then
                    Return "Unknown"
                Else
                    Return DataSourceType.Name
                End If
    Can be shortened to:
    Code:
                Return If(DataSourceType Is Nothing, "Unknown", DataSourceType.Name)

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,406

    Re: How to have a content collection on a user control that has a prop refs another c

    OT, this doesn't seem to make sense:
    vb.net Code:
    1. Dim DataSourceType = TryCast(BindingSource?.DataSource, Type)
    How could you ever cast a data source as Type when no data source would ever inherit Type? If you want the type of the data source then shouldn't that be:
    vb.net Code:
    1. Dim DataSourceType = BindingSource?.DataSource?.GetType()
    Assuming so, that whole ToString implementation could be changed to:
    vb.net Code:
    1. Return If(BindingSource?.DataSource?.GetType().Name, "Unknown")

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,406

    Re: How to have a content collection on a user control that has a prop refs another c

    Quote Originally Posted by Peter Swinkels View Post
    While this doesn't answer your question I have a suggestion:

    Code:
                If DataSourceType Is Nothing Then
                    Return "Unknown"
                Else
                    Return DataSourceType.Name
                End If
    Can be shortened to:
    Code:
                Return If(DataSourceType Is Nothing, "Unknown", DataSourceType.Name)
    and that can be shortened to:
    Code:
                Return If(DataSourceType?.Name, "Unknown")

  5. #5

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,373

    Re: How to have a content collection on a user control that has a prop refs another c

    Actually jmcilhinney it does = Type if you do it in the designer and set it to Object.
    .. it then provides the properties of that type to other controls for use.
    Then at runtime you fill it with an Enumerable(Of T) to populate everything with data..

    Peter Swinkels - I know this ... I would actually just have one line (as below) ... my real implementation has other stuff in the block .. so think it is easier in my real case to use a block.
    VB Code:
    1. Return If(TryCast(BindingSource?.DataSource, Type).?Name, "Unknown")

    Either way, neither of these answer the question
    Kris

    EDIT:.. I updated the sample - even though this had nothing to do with the question

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,406

    Re: How to have a content collection on a user control that has a prop refs another c

    Quote Originally Posted by i00 View Post
    Actually jmcilhinney it does = Type if you do it in the designer and set it to Object.
    .. it then provides the properties of that type to other controls for use.
    Then at runtime you fill it with an Enumerable(Of T) to populate everything with data..
    Interesting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width