开发者

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜