HI folks,

I have 2 questions ;

1) i have 2 groupBox s and what i want is when i select a ( listbox item or radiobutton) in the 1st groupBox it disable ( or clear ) automatically the 2nd groupBox or the other fields ?

2) How can i clear all the fields in the Winform after clicking on my "Submit: button ?


thank you very much

1. - this will disable other group box if you select listbox item :

private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
	if (listBox1.SelectedIndex > -1) 
	{
		groupBox1.Enabled = false;
	}
}

- this will disable other group box if you select radio button :

private void radioButton1_CheckedChanged_1(object sender, System.EventArgs e)
{
	if (radioButton1.Checked == true) 
	{
		groupBox1.Enabled = false;
	}
}

2. this following code will clear all textbox in your form:

public void ClearControl(Control root)
{
	foreach (Control ctrl in root.Controls) 
	{
		ClearControl(ctrl);
		if (ctrl is TextBox) 
		{
			((TextBox)ctrl).Text = string.Empty;
		}
	}
}

you can call this function in the last of your codes in submit button.
ex:

private void Submit_Click(object sender, System.EventArgs e)
{
        ...... // Your codes
	ClearControl(this);
}

thanks everybody for the help, i will try that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.