|
-
Jul 28th, 2009, 10:37 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Control.Validated
Is there anyway to check if a Control has been validated yet?
I have some code that I want to run when the Selected of a TabControl fires off.
The thing is, that I have TabPages added to the TabControl at the beginning of runtime, which then triggers the Selected event before the control is completely existent, which means the Sub I have that also happens to reference the control during that event errors out because there is technically not an instance of the control completely finished building so it says I don't have a correct reference set to that object.
So basically, I want to be able to check in the Sub if the control has been Validated, or maybe even created or whatever is going on.
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jul 28th, 2009, 11:06 PM
#2
Re: Control.Validated
How do you usually check whether an object exists?
vb.net Code:
If myObj IsNot Nothing Then 'Use myObj here. End If
-
Jul 28th, 2009, 11:18 PM
#3
Thread Starter
Fanatic Member
Re: Control.Validated
Here's my code:
vb Code:
If My.Settings.TabOrder IsNot Nothing AndAlso My.Settings.TabOrder.Count > 0 Then 'Check if there is a tab order stored 'Removes pages from tabcontrol, stores them and inserts tabs into new order Dim pages As New Collection(Of cTabPage) pages.Add(CType(tabPage1, cTabPage)) pages.Add(CType(tabPage2, cTabPage)) pages.Add(CType(tabPage3, cTabPage)) pages.Add(CType(tabPage4, cTabPage)) pages.Add(CType(tabPage5, cTabPage)) padControl.TabPages.Clear() For Each o As Object In My.Settings.TabOrder Select Case o.ToString Case "tabPage1" padControl.TabPages.Add(pages(0)) Case "tabPage2" padControl.TabPages.Add(pages(1)) Case "tabPage3" padControl.TabPages.Add(pages(2)) Case "tabPage4" padControl.TabPages.Add(pages(3)) Case "tabPage5" padControl.TabPages.Add(pages(4)) End Select Next End If
vb Code:
Public Sub setTitleBar() If padControl IsNot Nothing Then With My.Settings If .TitleBarDisplayPad = 0 Then Me.Text = "TrayPad" ElseIf .TitleBarDisplayPad = 1 And .TitleBarRemoveTrayPad = 0 Then Me.Text = "TrayPad - " & padControl.SelectedTab.Text ElseIf .TitleBarRemoveTrayPad = 1 Then Me.Text = padControl.SelectedTab.Text End If End With End If End Sub
vb Code:
Private Sub padControl_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles padControl.Selected setTitleBar() End Sub
The first block of code is what is triggering the Selected event for padControl.
The second block of code is the Sub where I have the code I want done.
The third block is pretty obvious.
Because of block 1, block 3 is triggered each time a tab is readded to the padControl.
Even though I enclosed the Sub code with what you suggested, it's still giving me an error.
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jul 28th, 2009, 11:40 PM
#4
Re: Control.Validated
Instead of saying something like "errors out", please provide the type of exception and the error message. Is it a NullReferenceException? An InvalidOperationException? Something else? Exactly which line does the error occur on? If we have all the relevant information in the first place then we don't have to guess or make assumptions.
-
Jul 28th, 2009, 11:41 PM
#5
Thread Starter
Fanatic Member
Re: Control.Validated
"NullReferenceException" on "Me.Text = "TrayPad - " & padControl.SelectedTab.Text"
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jul 28th, 2009, 11:46 PM
#6
Re: Control.Validated
It's a NullReferenceException so have you checked which reference is null? You're already testing padControl in code so it's not going to be that, which doesn't leave many options. The only other references are Me, which is obviously not null, and padControl.SelectedTab.
-
Jul 28th, 2009, 11:49 PM
#7
Thread Starter
Fanatic Member
Re: Control.Validated
:/ How can the SelectedTab be null? The Selected event got raised. Doesn't the control have to exist to raise an event on it?
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jul 29th, 2009, 12:00 AM
#8
Re: Control.Validated
I think a better way would be to get the selected TobPage text in the Selected event handler of the TabControl and pass it as a parameter to the setTitleBar method. It might be that the selected event happens befor the SelectedTab property of the TabControl is set.
vb Code:
Private Sub TabControl1_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControl1.Selected
Me.setTitleBar(e.TabPage.Text)
End Sub
Public Sub setTitleBar(ByVal tabText As String)
'....
'....
'....
End Sub
-
Jul 29th, 2009, 12:05 AM
#9
Thread Starter
Fanatic Member
Re: Control.Validated
hmm..ok i see.
I always think of a control as being a whole thing that has to be complete to exist, but i guess that isn't true. I've looked inside a custom control once and mssed with it, but I don't do it enough to always be thinking of how that all really works. even in a control there is procedural type code, so things have to come before others. 
Thanks, that makes more sense. I guess I'll just have to play with it.
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jul 29th, 2009, 12:29 AM
#10
Thread Starter
Fanatic Member
Re: Control.Validated
Yup, got it to work that way. Thanks for the help.
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|