Results 1 to 7 of 7

Thread: 'clear' function won't work

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    'clear' function won't work

    ok, I have several functions of which each clear (initialize) each individual control encountered on a form (textbox, combobox, etc)

    They work like a charm UNLESS those controls are on a tab that is on a tab. ex. I have a main tab control and the controls (tabs and its controls) get cleared fine. I have other tab controls sitting on that main one. THOSE tabs and the controls sitting on those aren't getting touched. following are the basic fuctions:


    VB Code:
    1. '***************************************************************************************************
    2.         'Initialize the tab pages
    3.  
    4.         For Each ctrl As Control In Me.Controls
    5.             If TypeOf ctrl Is TabControl Then
    6.  
    7.                 ClearTabControl(ctrl)
    8.  
    9.             End If
    10.  
    11.         Next

    VB Code:
    1. Public Sub ClearListBox(ByVal box As ListBox)
    2.         'Purpose    :   Clear a list box of all items
    3.         'Accepts    :   listbox control
    4.         'Notes      :  
    5.         box.Items.Clear()
    6.     End Sub
    7.  
    8.     Public Sub ClearTabControl(ByVal tc As TabControl)
    9.         'Purpose    :   clears all tabpages on a tabpage control
    10.         'Accepts    :   control as tabcontrol
    11.         'Returns    :  
    12.         'Notes      :  
    13.  
    14.         For Each ctrl As Control In tc.Controls
    15.             Try
    16.                 If TypeOf ctrl Is TabPage Then
    17.                     ClearTab(ctrl)
    18.                 End If
    19.             Catch ex As Exception
    20.  
    21.             End Try
    22.         Next
    23.  
    24.     End Sub
    25.  
    26.     Public Sub ClearTab(ByVal tab As TabPage)
    27.         'Purpose    :   Clears an entire tab control of data
    28.         'Accepts    :   tabpage control
    29.         'Notes      :   this sub calls on other subs to do the work
    30.  
    31.         For Each ctrl As Control In tab.Controls
    32.  
    33.             Try
    34.                 'Clear all textboxes
    35.                 If TypeOf ctrl Is TextBox Then
    36.                     TextBoxClear(ctrl)
    37.                 End If
    38.  
    39.                 'Next, ComboBoxes
    40.                 If TypeOf ctrl Is ComboBox Then
    41.                     ComboBoxClear(ctrl)
    42.                 End If
    43.  
    44.                 'Next, Groupboxes
    45.                 If TypeOf ctrl Is GroupBox Then
    46.                     GroupBoxClear(ctrl)
    47.                 End If
    48.  
    49.                 'Next, other Tabs
    50.                 If TypeOf ctrl Is TabPage Then
    51.                     ClearTab(ctrl)
    52.                 End If
    53.  
    54.                 'Next, Listboxes
    55.                 If TypeOf ctrl Is ListBox Then
    56.                     ClearListBox(ctrl)
    57.                 End If
    58.             Catch
    59.             End Try
    60.         Next
    61.  
    62.     End Sub
    63.  
    64.     Public Sub ComboBoxClear(ByVal Box As ComboBox)
    65.         'Purpose    :   Resets a combobox to the first item in the collection list
    66.         'Accepts    :   combox as argument
    67.         'Notes      :   This doesn't delete any info, it just resets the box
    68.  
    69.         Try
    70.             Box.Text = Box.Items.Item(0)
    71.  
    72.         Catch
    73.  
    74.         End Try
    75.  
    76.     End Sub
    77.  
    78. Public Sub GroupBoxClear(ByVal groupbox As GroupBox)
    79.         'Purpose    :   Clear all textboxes within a groupbox control
    80.         'Accepts    :   groupbox as argument
    81.         'Notes      :  
    82.  
    83.  
    84.         For Each ctrl As Control In groupbox.Controls
    85.  
    86.             Try
    87.                 If TypeOf ctrl Is TextBox Then
    88.  
    89.                     TextBoxClear(ctrl)
    90.  
    91.                 End If
    92.  
    93.                 If TypeOf ctrl Is ComboBox Then
    94.  
    95.                     ComboBoxClear(ctrl)
    96.  
    97.                 End If
    98.  
    99.             Catch
    100.  
    101.             End Try
    102.  
    103.         Next
    104.  
    105.  
    106.     End Sub
    107.  
    108.  Public Sub TextBoxClear(ByVal box As TextBox)
    109.         box.Text = String.Empty
    110.     End Sub

    apparantly, i'm missing something when program control goes to TAB CONTROL .

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    See if this is what you want !
    Attached Files Attached Files

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    that works but it still doesn't catch any tab control that are stapled onto the other one.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by thephantom
    that works but it still doesn't catch any tab control that are stapled onto the other one.
    I took it you need to clear textboxes or any control on the main tab and also a child tab that resides inside the main tab . Sorry , I think I didn't understand how you set up your controls . Can you explain more ?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    sure

    ok, I have a MAIN tab control. and the functions work great for the tab pages, the controls and anything else that sits on the MAIN control.

    but, I have a second tab control that sits on the main tab control and it doesn't get touched. I will post a picture of it in a second. It's weird though because there is a similar secondary tab control that DOES get worked on

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    the top row is the main tab control
    the bottom row is the secondary. that is the one that doesn't get it's contents cleared.
    Attached Files Attached Files

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Is the secondary tabcontrol inside (part of ) the main tabcontrol ? If yes , then the sample code I sent should solve this problem .
    Just to double check that you have panel or groupbox on the secondary tab ?

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