Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove/Add UserControls from Main Form

Status
Not open for further replies.

pewilson

Technical User
Mar 9, 2001
52
0
0
US
I am having trouble getting one usercontrol to remove and adding another usercontrol onto my main form. This was working like it was intended just last week I have included the code for the main form "frmMain" and the code from the report Search usercontrol "ucReportSearch". The code fails when it reaches the RemovePanel in the AddReportContainer procedure. For some reason it is not recognizing my local vaiable ItemPanel in the RemovePanel. Instead of displaying the reference object objReportContainer it will display ReportTrackermMaster.objReportContainer when I do a step-through during debugging. Not sure why this is happening.

frmMain
Code:
[COLOR=blue]Public Class[/color] frmMain
[COLOR=green]' Declare refernce to User Control[/color] 
[COLOR=blue]Private WithEvents[/color] objReportContainer [COLOR=blue]As[/color] ucReportContainer

[COLOR=green]' Declare local variable to store the current User Control[/color]
[COLOR=blue]Dim[/color] ItemPanel [COLOR=blue]As[/color] Control

	[COLOR=blue]Public Sub[/color] AddReportContainer()
	    RemovePanel()
	    objReportContainer = [COLOR=blue]New[/color]ucReportContainer
	    pnlMain.Controls.Add(objReortContainer)
	    objReportContainer.Dock = DockStyle.Fill
	    [COLOR=green]'Set the current User Control to the control variable[/color]
	    ItemPanel = objReportContainer
	[COLOR=blue]End Sub[/color]


	[COLOR=blue]Private Sub[/color] RemovePanel()
	    [COLOR=green]'Remove the panel if it is the current panel[/color]
	    [COLOR=blue]If Not[/color] IsNothing(ItemPanel) [COLOR=blue]Then[/color]
	    ItemPanel.Dock = DockStyle.None
	    pnlMain.Controls.Remove(ItemPanel)
	[COLOR=blue]End Sub[/color]

[COLOR=blue]End Class[/color]


Im not sure if this is the root care to my problem when application executes frmMain.AddReportContainer
this is where the trouble begins.
objReportSearch
Code:
[COLOR=blue]Private Sub[/color] lvList_DoubleClick([COLOR=blue]ByVal[/color] sender [COLOR=blue]As[/color] System.Object, [COLOR=blue]ByVal[/color] e [COLOR=blue]As[/color] System.EventArgs) [COLOR=blue]Handles[/color] lvList.DoubleClick
	[COLOR=blue]My[/color].Settings.gReportID = lvList.SelectedItems.Item(0).Tab
	frmMain.AddReportContainer()
[COLOR=blue]End Sub[/color]



Your assistance is greatly needed and thanks in advance.

Paul
paul_wilson74@hotmail.com
 
Any particular reason why you need to store objReportContainer to ItemPanel?

Code:
    Public Sub AddReportContainer()
        RemovePanel()
        objReportContainer = New ucReportContainer
        pnlMain.Controls.Add(objReortContainer)
        objReportContainer.Dock = DockStyle.Fill
    End Sub

    Private Sub RemovePanel()
        'Remove the panel if it is the current panel
        For Each c As Control In pnlMain
            If TypeOf c Is ucReportContainer Then
               pnlMain.Controls.Remove(c)
            EndIf
        Next 'c
        objReportContainer = Nothing
    End Sub

Good Luck.
 
I have 5 other usercontrol forms that are being used. That is why I chose to reference the current UserControl to the ItemPanel that way I could pass the ItemPanel through the RemovePanel procedure.

Paul
paul_wilson74@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top