Custom Panel Does Not Work In Designer

JoeBuntu

Member
Joined
Jun 20, 2009
Messages
8
Programming Experience
1-3
I created class called BindedPanel that inherits from System.Windows.Forms.Panel

My problem is that the class does not seem to build. When I do build the project builds successfully but the BindedPanel does not show up in my toolbox and if I manually change the code in the .designer file to declare my panel as a BindedPanel the designer gives me the following message:
"Could not find type ExelInvControls.BindedPanel .... Please make sure that the assembly that contains this type is referenced. If this type is part of your development project, make sure the project has been successfully built."

I have tried building the class in the same project as the form I am trying to use it in and I have also tried building it in a seperate project, neither way works. I have successfully used other custom controls, such as combo boxes and UserControls, just can't get this one to work.

Here is the Class:
VB.NET:
Expand Collapse Copy
Public Class BindedPanel(Of T As BindedRecord, I)
    Inherits System.Windows.Forms.Panel

    Private m_recordStartHeight As Integer 'height of first record
    Private m_recordStartLocation As System.Drawing.Point 'location of first record
    Private m_LastRecordLocation As System.Drawing.Point 'location of last record
    Private m_buttonAddLocation As System.Drawing.Point 'btnAddRecords location at design
    Private m_buttonPadding As Integer 'distance of btnAddRecord to records
    Private m_CurBlankRecord As T
    'Current Blank Record
    Private btnAddRecord As Button

    Public Sub SetFirstRecordPosition(ByVal ucRecord As UserControl, ByVal btnAdd As Button)
        'sets starting position of records based on record planted in designer
        Me.btnAddRecord = btnAdd
        m_recordStartLocation = ucRecord.Location
        m_recordStartHeight = ucRecord.Height
        m_buttonAddLocation = btnAddRecord.Location
        m_buttonPadding = btnAddRecord.Location.Y - ucRecord.Location.Y
        Me.Controls.Remove(ucRecord)

    End Sub

    Public Function AddBlankRecord() As I 'IHasKey
        'Add a blank record
        Dim addNewRecord As Boolean = False
        Dim newDetailItem = Activator.CreateInstance(GetType(I))
        If m_CurBlankRecord Is Nothing Then
            addNewRecord = True
        ElseIf m_CurBlankRecord.IsPartValidated Then
            addNewRecord = True
        End If

        If addNewRecord Then
            Dim newRecord = Activator.CreateInstance(GetType(T), newDetailItem)
            newRecord.Location = m_LastRecordLocation
            Me.Controls.Add(newRecord)
            m_CurBlankRecord = newRecord

            'Me.m_currentBom.Items.Add(newBomDetailItem.PartId, newBomDetailItem)
            m_LastRecordLocation.Y += m_recordStartHeight

            'move button
            Dim buttonLocation As System.Drawing.Point = m_buttonAddLocation
            buttonLocation.Y = m_LastRecordLocation.Y - m_recordStartHeight + m_buttonPadding
            btnAddRecord.Location = buttonLocation
        Else
            MsgBox("Last added record must contain valid data before adding" & vbCr & _
                   "a new record")
            newDetailItem = Nothing
        End If
        Return newDetailItem
    End Function

    Public Sub ResetRecords(ByVal PartsList As Array)
        Dim TrashRecords As New List(Of T)

        Me.SuspendLayout()
        'Collect all records for removal
        For Each ctr As Control In Me.Controls
            If TypeOf ctr Is T Then
                TrashRecords.Add(ctr)
            End If
        Next

        'Now Remove them
        For Each item In TrashRecords
            Me.Controls.Remove(item)
        Next

        Dim newRecord As T
        Dim RecordLocation As System.Drawing.Point = m_recordStartLocation

        'Now create new records
        For Each Item In PartsList
            newRecord = Activator.CreateInstance(GetType(T), Item)
            newRecord.Location = RecordLocation
            Me.Controls.Add(newRecord)
            RecordLocation.Y += m_recordStartHeight
        Next

        m_LastRecordLocation = RecordLocation
        'move add record button
        Dim buttonLocation As System.Drawing.Point = m_buttonAddLocation
        buttonLocation.Y = m_LastRecordLocation.Y - m_recordStartHeight + m_buttonPadding
        btnAddRecord.Location = buttonLocation
        m_CurBlankRecord = Nothing


        Me.ResumeLayout()
        Me.Refresh()
    End Sub
End Class
 
I wanted to add that even though I cannot use the class with the designer the form I am using it in compiles successfully and the program works fine. But not being able to use the designer is a real headache. Thanks
 
Came Up with solution

Funny how I figure something out half an hour after posting the question. I guess the designer does not like generic types so by creating a new class that inherits from BindedPanel that specifies the types the new class showed up in my toolbox and I was able to use the control in the designer. I hope this helps someone else if nothing else.

This class will work in designer:
VB.NET:
Expand Collapse Copy
Public Class BindedBomPanel
    Inherits BindedPanel(Of UserControl_BomRecord, BomDetailItem)

End Class
 
Back
Top