0

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

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by korssane
0

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);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.