Ayyappan Anbalagan
Ayyappan Anbalagan

Reputation: 11292

How to control the groupbox items in .NET winforms?

I am using .NET winforms.

I have a groupBox that contains a set of controls like textbox, dropdown....

How can I control the fields which are available in groupBox?

Example:

I need to clear all the control fields.

Upvotes: 2

Views: 1278

Answers (1)

Hans Olsson
Hans Olsson

Reputation: 54999

You will have to write all the code as normal, but you might be able to use a loop for certain things as shown in this code (note, this code is just to show the structure, it's not going to compile as is):

foreach(Control ctrl in groupbox1.Controls)
{
    if(typeof ctrl is TextBox)
    {
         ctrl.Text = "";
    }
    elseif // listview
    {
        ListView l = ctrl as ListView;
        l.Items.Clear()
    }
}

It might be worth creating your own user control that contains the groupbox with all the other controls inside, so that you don't end up with too much code in one form.

Upvotes: 2

Related Questions