Results 1 to 10 of 10

Thread: [RESOLVED] Control.Validated

  1. #1

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    Resolved [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]

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Control.Validated

    How do you usually check whether an object exists?
    vb.net Code:
    1. If myObj IsNot Nothing Then
    2.     'Use myObj here.
    3. End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    Re: Control.Validated

    Here's my code:
    vb Code:
    1. If My.Settings.TabOrder IsNot Nothing AndAlso My.Settings.TabOrder.Count > 0 Then
    2.             'Check if there is a tab order stored
    3.             'Removes pages from tabcontrol, stores them and inserts tabs into new order
    4.             Dim pages As New Collection(Of cTabPage)
    5.             pages.Add(CType(tabPage1, cTabPage))
    6.             pages.Add(CType(tabPage2, cTabPage))
    7.             pages.Add(CType(tabPage3, cTabPage))
    8.             pages.Add(CType(tabPage4, cTabPage))
    9.             pages.Add(CType(tabPage5, cTabPage))
    10.             padControl.TabPages.Clear()
    11.             For Each o As Object In My.Settings.TabOrder
    12.                 Select Case o.ToString
    13.                     Case "tabPage1"
    14.                         padControl.TabPages.Add(pages(0))
    15.                     Case "tabPage2"
    16.                         padControl.TabPages.Add(pages(1))
    17.                     Case "tabPage3"
    18.                         padControl.TabPages.Add(pages(2))
    19.                     Case "tabPage4"
    20.                         padControl.TabPages.Add(pages(3))
    21.                     Case "tabPage5"
    22.                         padControl.TabPages.Add(pages(4))
    23.                 End Select
    24.             Next
    25.         End If

    vb Code:
    1. Public Sub setTitleBar()
    2.         If padControl IsNot Nothing Then
    3.             With My.Settings
    4.                 If .TitleBarDisplayPad = 0 Then
    5.                     Me.Text = "TrayPad"
    6.                 ElseIf .TitleBarDisplayPad = 1 And .TitleBarRemoveTrayPad = 0 Then
    7.                     Me.Text = "TrayPad - " & padControl.SelectedTab.Text
    8.                 ElseIf .TitleBarRemoveTrayPad = 1 Then
    9.                     Me.Text = padControl.SelectedTab.Text
    10.                 End If
    11.             End With
    12.         End If
    13.     End Sub

    vb Code:
    1. Private Sub padControl_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles padControl.Selected
    2.         setTitleBar()
    3.     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]

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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]

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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]

  8. #8
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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:
    1. Private Sub TabControl1_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControl1.Selected
    2.     Me.setTitleBar(e.TabPage.Text)
    3. End Sub
    4.  
    5. Public Sub setTitleBar(ByVal tabText As String)
    6.     '....
    7.     '....
    8.     '....
    9. End Sub

  9. #9

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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]

  10. #10

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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
  •  



Click Here to Expand Forum to Full Width