How to Search Through a C# DropDownList Programmatically

后端 未结 9 1200
一生所求
一生所求 2021-02-14 05:24

I am having a hard time figuring out how to code a series of \"if\" statements that search through different dropdownlists for a specific value entered in a textbox. I was able

9条回答
  •  -上瘾入骨i
    2021-02-14 06:04

    If you don't want to use LINQ:

            List dropDowns = new List();
            dropDowns.Add(comboBox1);
            dropDowns.Add(comboBox2);
    
            bool found = false;
            ComboBox foundInCombo = null;
            int foundIndex = -1;
    
            for (int i = 0; i < dropDowns.Count && found == false; i++)
            {
                for (int j = 0; j < dropDowns[i].Items.Count && found == false; j++)
                {
                    if (item == textBox1.Text)
                    {
                        found = true;
                        foundInCombo = dropDowns[i];
                        foundIndex = j;
                    }
                }
            }
    

提交回复
热议问题