locked
Identifying the custom controls assigned to the main custom control RRS feed

  • Question

  • User1918001915 posted

    Thank you in advance for any assistance in this.

    I posted this in the custom control section of the forms but was told this would be the more appropriate place.  What I am trying to do is construct a control that can inherit a number of other custom controls.  Think of this logic:  dropdownlist.add(listitem) >> panel.add(dropdownlist) etc.

    I can create a custom control that has basic properties and then handle all of the logic from there.

    I started from here: http://aspnet.4guysfromrolla.com/articles/102302-1.2.aspx

    There is some extremely clean code that Scott uses in building a custom usercollection control that allows the control to collect items by taking on the arraylist properties.

    My problem is that while I seem to be OK at the lower levels, it is at the top that I am unable to properly program the class to handle the variable number of controls below it.

    Below is the guts of the code, I hope this explains better what I am trying to do.  The error message is noted during the Generate Sub of the Main control class.

    If anyone can aid in a solution to the syntax error, I'd greatly appreciate it.


    DEFAULT.ASPX.VB

        'code fragment, excluding all imports, etc
        'declare all of the controls here
        
        Dim MC as new MainControl
        Dim AA as new ControlA
        Dim BB as new ControlB
        Dim CC as new ControlC
        
        'Setting basic properties of controls
        BB.IsHeader = True
        AA.Title = "Test Title"
        
        'Setting the parameters of CC
        
        CC.Text = "Alpha"
        CC.Type = "String"
        
        'Adds a Control C to a Control B
        BB.Add(CC)
        
        'Another Contorl C
        
        CC = new ControlC
        CC.Text = "Beta"
        CC.Type = "String"
        
        'Adding another Control C to control B
        BB.Add(CC)
        
        'Ok, we are now adding everything so we can construct our main control
        AA.Add(BB)
        MC.Add(AA)
        
        MC.Generate




    APP_CODE FILE
    'other than logic, key imports and inherits are in this code.

    Imports System
    Imports System.Data
    Imports System.Collections
    Imports System.IO
    Imports System.Web
    Imports Microsoft.VisualBasic

    NameSpace Seriesofcontrols

        Public Class MainControl
            Inherits Arraylist
            
            #Region "localVariables"
                Private STRPropertyA As String = ""
                Private STRPropertyB As String = ""
                Private STRPropertyC As String = ""

            #End Region
        
            Property PropertyA() As String
                Get
                Return STRPropertyA
                End Get
                Set(ByVal value As String)
                STRPropertyA = value
                End Set
            End Property

            Property PropertyB() As String
                Get
                Return STRPropertyB
                End Get
                Set(ByVal value As String)
                STRPropertyB = value
                End Set
            End Property

            Property PropertyC() As String
                Get
                Return STRPropertyC
                End Get
                Set(ByVal value As String)
                STRPropertyC = value
                End Set
            End Property


            Sub New()
                'new only generates a new instance
            End Sub
            
            Sub Generate()
                'This is the execution sub.
                
                'generic beginning stuff
                
                For Each ControlA in Maincontrol
                    'Error message: MainControl is a type and cannot be used as an expression
                
                    For each ControlB in ControlA
                        'no problems here, since there are controlBs added on controlA
                        
                        For Each ControlC in Control B
                            'again, no problems - controlCs are added to controlB
                            
                        Next
                    Next
                Next
            End Sub

        End Class
        
        
        
        Public Class ControlA
            Inherits ArrayList


            #Region "localVariables"

                Private EWSTitle As String = "Sheet1"

            #End Region

            Property Title() As String
                Get
                Return EWSTitle
                End Get
                Set(ByVal value As String)
                EWSTitle = value
                End Set
            End Property

            Public Sub New()

            End Sub
        
        End Class
        
        Public Class ControlB
        
               Inherits ArrayList

            #Region "localVariables"
                Private ERIsHeader As Boolean = False

            #End Region

            Property IsHeader() As Boolean
                Get
                Return ERIsHeader
                End Get
                Set(ByVal value As Boolean)
                ERIsHeader = value
                End Set
            End Property

            Public Sub New()
                'nothing in this function, simply declares as a new item
            End Sub
        
        End Class
        
        Public Class ControlC

            #Region "localvariables"
                Private TheText As String = ""
                Private TheType As String = "String"
            #End Region
            Property Text() As String
                Get
                Return TheText
                End Get
                Set(ByVal value As String)
                TheText = value
                End Set
            End Property

            Property Type() As String
                Get
                Return TheType
                End Get
                Set(ByVal value As String)
                TheType = value
                End Set
            End Property    
        
            Public Sub New()
                'does nothing, just declares a new item
            End Sub
        
        End Class
        
    End Namespace

    Friday, May 29, 2009 11:03 AM

Answers

  • User-2106054853 posted

    Hi,

     Please try this:

    For Each c As Object In Me                     
     

    ...

     

    For other VB.NET syntax issues please ask in VB.NET forum:

    http://forums.asp.net/36.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 1, 2009 3:11 AM