---
title: "Clear Checkboxes and Textboxes in Splitcontainer - C#"  
description: "Clear Checkboxes and Textboxes in Splitcontainer - C#"  
author: "Anonymous User"  
published: 2013-12-23  
updated: 2013-12-23  
canonical: https://www.mindstick.com/forum/1826/clear-checkboxes-and-textboxes-in-splitcontainer-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Clear Checkboxes and Textboxes in Splitcontainer - C#

I'm attempting to clear all the checkboxes and textboxes in the first [panel](https://www.mindstick.com/blog/11988/restructuring-corporate-offenses-government-appointed-panel-suggests-in-house-adjudication-system) of my splitcontainer but I'm having no luck as nothing seems to happen.

```
private void clearSettingsBtn_Click(object sender, EventArgs e){    foreach (Control c in splitContainer1.Panel1.Controls)    {        if (c is CheckBox)        {            ((CheckBox)c).Checked = false;        }        else if (c is TextBox)        {            ((TextBox)c).Clear();        }    }}
```

Have I missed something?

## Replies

### Reply by Pravesh Singh

Hi Ankita,

Actually your code is pretty OK, there should be another problem like wrong panel or more likely there would be another container in your panel, like a GroupBox, which in that case (another container) you should iterate through that container.

In case you have a container inside the panel a simple code could be like this:

```
            foreach (Control control in splitContainer1.Panel2.Controls)        {            if (control is GroupBox)            {                foreach (Control child in (control as GroupBox).Controls)                {                    if (child is CheckBox)                    {                        ((CheckBox)control).Checked = false;                    }                    else if (child is TextBox)                    {                        (control as TextBox).Clear();                    }                }            }        }
```

But if you want to write a more general code, you should check for each container, i.e. GroupBox, Panel etc.


---

Original Source: https://www.mindstick.com/forum/1826/clear-checkboxes-and-textboxes-in-splitcontainer-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
