簡體   English   中英

C# 項目列表填滿時無法更新 ComboBox

[英]C# can't update ComboBox when Item List is filled

我有一個 function 清除表單上的所有組合框,然后嘗試更新文本。 僅當項目列表中沒有項目時才會顯示新文本。 有誰知道出了什么問題?

我從項目中刪除了所有功能,因此只有必要的部分可用。

https://www.dropbox.com/s/ibst7enrteyk9jb/Digitales_Auftragsformular.zip?dl=0

該項目已附上。 簡單地開始,go 到標簽“Werkzeuganfrage”有兩個紅色的組合框。 一個沒有項目 = 工作,一個項目不工作。

 public Oberflaeche()
    {
        InitializeComponent();           


        List<ComboBox> myComboBoxes = GetControlsByType<ComboBox>(this, typeof(ComboBox));

        foreach (ComboBox txt in myComboBoxes)
        {
            //txt.Text = "";
            txt.SelectedIndex = -1;

        }
        Werkzeuganfrage_Combobox_rhino1_1.Text = "Rhino1_1";
        Werkzeuganfrage_Combobox_rhino1_2.Text = "Rhino1_2";

        comboBox1.Text = "Rhino1_1";
        comboBox2.Text = "Rhino1_2";
    }



    public List<T> GetControlsByType<T>(Control container, Type type)
    {


        List<T> result = new List<T>();
        foreach (Control c in container.Controls)
        {
            if (c.GetType() == type)
            {
                result.Add((T)Convert.ChangeType(c, typeof(T)));
            }

            if (c.HasChildren)
            {
                result.AddRange(GetControlsByType<T>(c, type));
            }
        }
        return result;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM