Entwickler-Ecke

Basistechnologien - Comboboxen durchlaufen


Talemantros - Mi 31.12.14 15:01
Titel: Comboboxen durchlaufen
Hallo,
würde gern Comboboxen durchlaufen um deren Inhalt abzufragen.

Leider klappt dies nicht

Soweit bin ich


C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
            foreach (Control control in kryptonGroupBox2.Controls)
            {
                if (control is ComboBox)
                {
                    MsgBox.MsgAusgabe.ShowInformation(((ComboBox)control).Text);
                }
            }


Hat da jemand eine Idee für mich?

Danke

Und guten Rutsch euch allen nachher


Ralf Jansen - Mi 31.12.14 16:19

Sind deine Controls den auch Combobox(en)? Oder etwas anderes (z.B. von Krypton) das nur so aussieht wie eine ComboBox.
Liegen die direkt auf dem kryptonGroupBox2 Control? Wenn nicht und da sind noch Container Controls dazwischen musst du die rekursiv durchlaufen.


Talemantros - Fr 02.01.15 11:33

Hallo Ralf,
danke für den Tipp mit dem dem KryptonCombobox und dem Rekursiv.

Habe es jetzt wie folgt lauffähig und kann damit weiter arbeiten:


C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
        private void btnOktabiner_Click(object sender, EventArgs e)
        {
            ReadControls(this);
        }

        private void ReadControls(Control form)
        {
            foreach (Control control in form.Controls)
            {
                if ((control is KryptonComboBox) && (control.Text != string.Empty))
                {
                    MsgBox.MsgAusgabe.ShowInformation(((KryptonComboBox)control).Text);
                }
                else
                    ReadControls(control);
            }
        }