2017-06-03 1 views
0

Ich habe tabcontrol von drei Registerkarten und jede Registerkarte enthält Textbox und ich möchte alle Textfelder in jeder Registerkarte löschen und ein Klick auf Schaltfläche (Schaltfläche Ereignis oder eine alternative Möglichkeit, alle Textfelder zu löschen)Löschen von Textfeldern in tabcointrols in vb.net

i bereits viele haben Code jedoch, dass nur wirksam für die ersten Reiter nur

Private Sub ClearFields(ByVal cntr As Control) 
    For Each page As TabPage In TabControl1.TabPages 
     For Each ctl As Control In page.Controls 
      If TypeOf ctl Is TextBox Then 
       ctl.Text = "" 
      End If 
      If TypeOf ctl Is ComboBox Then 
       ctl.Text = "" 
      End If 
      If ctl.HasChildren Then 
       For Each thing As Control In ctl.Controls 
        If TypeOf thing Is TextBox Then 
         thing.Text = "" 
        End If 
       Next 
      End If 
     Next 
    Next 
End Sub 
+0

Fast jeder Beitrag zu finden unter ** Ähnliche ** beschäftigt sich mit dieser Art der Sache – Plutonix

Antwort

0

das aussehen sollte etwas mehr wie versucht:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    ClearTabControl(TabControl1) 
End Sub 

Private Sub ClearTabControl(ByVal tb As TabControl) 
    For Each page As TabPage In TabControl1.TabPages 
     ClearFields(page) 
    Next 
End Sub 

Private Sub ClearFields(ByVal cntr As Control) 
    For Each ctl As Control In cntr.Controls 
     If TypeOf ctl Is TextBox OrElse TypeOf ctl Is ComboBox Then 
      ctl.Text = "" 
     ElseIf ctl.HasChildren Then 
      ClearFields(ctl) 
     End If 
    Next 
End Sub 
+0

Vielen Dank, plz mich erinnern, wenn Sie Hilfe benötigen. – babin

0

Hier anot ist ihre Methode, die als Spracherweiterungsmethode eingerichtet wird. Erstellen Sie ein neues Codemodul, und ersetzen Sie den Standardcode durch den folgenden Code.

Public Module ControlExtensions 
    <Runtime.CompilerServices.Extension()> 
    Public Sub ClearSpecificControls(ByVal sender As Control) 
     Dim currentControl As Control = sender.GetNextControl(sender, True) 
     Dim cboControl As ComboBox = Nothing 

     Do Until currentControl Is Nothing 
      If TypeOf currentControl Is TextBox Then 
       currentControl.Text = "" 
      ElseIf TypeOf currentControl Is ComboBox Then 
       cboControl = CType(currentControl, ComboBox) 
       If cboControl.DataSource IsNot Nothing Then 
        cboControl.DataSource = Nothing 
       Else 
        cboControl.Items.Clear() 
       End If 
      End If 
      currentControl = sender.GetNextControl(currentControl, True) 
     Loop 
    End Sub 
End Module 

Löschen Sie alle TextBox- und ComboBox-Steuerelemente in TabControl1.

TabControl1.ClearSpecificControls 

Löschen Sie alle Steuerelemente in einem Formular

ClearSpecificControls 
Verwandte Themen