private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.AddRange (new string[]{"mohamed","Ahmed","Nader"});
comboBox2.Items.AddRange(new string[] { "mohamed", "Ahmed", "Nader" });
comboBox3.Items.AddRange(new string[] { "mohamed", "Ahmed", "Nader" });
}
private void EmptyCombo(Control C,string[] CombNames)
{
foreach(Control CombType in C.Controls)
{
if (CombType is ComboBox)
{
foreach (string name in CombNames)
{
if (CombType.Name == name)
{
(CombType as ComboBox).Text = "Choose Your Value";
}
}
if ((CombType as ComboBox).Text != "Choose Your Value")
{
(CombType as ComboBox).DataSource = null;
(CombType as ComboBox).Items.Clear();
}
}
else
{
if (CombType is GroupBox)
{
EmptyCombo(CombType, CombNames);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
EmptyCombo(this, new string[] {"comboBox1","comboBox3"});
}
}
}
{
comboBox1.Items.AddRange (new string[]{"mohamed","Ahmed","Nader"});
comboBox2.Items.AddRange(new string[] { "mohamed", "Ahmed", "Nader" });
comboBox3.Items.AddRange(new string[] { "mohamed", "Ahmed", "Nader" });
}
private void EmptyCombo(Control C,string[] CombNames)
{
foreach(Control CombType in C.Controls)
{
if (CombType is ComboBox)
{
foreach (string name in CombNames)
{
if (CombType.Name == name)
{
(CombType as ComboBox).Text = "Choose Your Value";
}
}
if ((CombType as ComboBox).Text != "Choose Your Value")
{
(CombType as ComboBox).DataSource = null;
(CombType as ComboBox).Items.Clear();
}
}
else
{
if (CombType is GroupBox)
{
EmptyCombo(CombType, CombNames);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
EmptyCombo(this, new string[] {"comboBox1","comboBox3"});
}
}
}
حمل المثال كامل
0 التعليقات
إرسال تعليق