Question tabPages.clear does not make sense

caouellet

New member
Joined
May 18, 2010
Messages
1
Location
Qubec city
Programming Experience
10+
Hi all

I have a form that display a tabcontrol in which I dynamically create tabpages. Each that page represent a display for the status of a led panel device (daktronics led display strip). I made a configuration window where I configure the access to the daktronics device entering IP, Port and 2 headers. The thing is as follow, at startup no problem when the tabcontrol.tabPages.clear() is called but if I try it after the startup I get a Object is not set to an instance of an object error. Funny thing is, I catch the exception and show the exception message and after that all is fine tabs are gone and new tabs are correctly created.

Code follows

Private Sub ConfigureDisplay()
Dim tmpPanel As AfficheurDisplayPanel = Nothing
Dim tmpTab As TabPage = Nothing

Try
tcMain.TabPages.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message, "Erreur")
End Try

For Each i As Integer In AfficheurDataList.Keys
tmpTab = New TabPage(AfficheurDataList(i).SiteDesc)
tmpTab.Parent = tcMain
tmpTab.Tag = AfficheurDataList(i).GrpNo
tmpPanel = New AfficheurDisplayPanel
tmpPanel.Dock = DockStyle.Fill
tmpPanel.Name = String.Concat("DisplayAfficheur", i)
AddHandler tmpPanel.cmdTest.Click, AddressOf cmdTest_Click

tmpTab.Controls.Add(tmpPanel)
Next
End Sub

Now of course I could just catch the exception and do nothing but thats not a proper way to go about it

Thnaks for your thoughts
 
Back
Top