# Visual Basic > Visual Basic .NET >  Clear comboboxes in a tab control

## Tesla1886

I have several tab controls with several tab pages each with several comboboxes.

When I need to clear the text of the combobox I tried setting the text property to "" and even tried setting it to nothing. Both worked for some but not all of the comboboxs.

So I tried the code below, it works for all comboboxes but only for the active tab, to clear the other tabs I have to repeat the process for each tab page.



```
Dim CBox As ComboBox
        For Each ctrl As Control In TabControl.SelectedTab.Controls
            If CBool(InStr(ctrl.GetType().ToString(), "ComboBox")) Then
                CBox = DirectCast(ctrl, ComboBox)
                CBox.Text = ""
            End If
        Next
```

Is there an easy way to clear all comboBoxes on all tabs in one process

Thank you

----------


## jmcilhinney

vb.net Code:
For Each tp As TabPage In myTabControl.TabPages
    For Each cb In tp.Controls.OfType(Of ComboBox)()
        cb.Selectedindex = -1
    Next
Next
That will work if the DropDownStyle is set to DropDownList, which it generally should be, unless you want the user to be able to type arbitrary text rather than select from the list.

If you want that to work for multiple TabControls then you can put them in a list somehow, e.g.

vb.net Code:
Dim tabControls = {TabControls1, TabControl2, TabControl3}
or:

vb.net Code:
Dim tabControls = Controls.OfType(Of TabControl)()
and then put the original code in another loop:

vb.net Code:
For Each myTabControl In tabControls
    '...
Next

----------

