Hallo,
ich bin neu hier und habe auch schon gleich eine Frage. Seit ein paar Tagen beschäftige ich mit mit C# und versuch ein Zusatzmodul für AutoCad zu erstellen. Dafür habe ich ein Form erstellt, in das der Anwender ein paar Zahlenwerte eingeben und in mehreren ComboBoxen etwas wählen muss.
Inhalt der comboBoxen:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39:
| public Form1() { InitializeComponent(); //Compobox1 füllen (firsttyp) Dictionary<string, string> firsttyp; firsttyp = new Dictionary<string, string>(); firsttyp.Add("0", "Latte"); firsttyp.Add("1", "Bohle"); firsttyp.Add("2", "Pfette"); BindingSource myBindingSource = new BindingSource(); myBindingSource.DataSource = firsttyp; comboBox1.DataSource = myBindingSource; comboBox1.DisplayMember = "Value"; comboBox1.ValueMember = "Key";
//Compobox2 füllen (Firstpunktausbildung) Dictionary<string, string> firstpunktausbildung; firstpunktausbildung = new Dictionary<string, string>(); firstpunktausbildung.Add("0", "Stumpfstoß"); firstpunktausbildung.Add("1", "Verblattung"); BindingSource myBindingSource2= new BindingSource(); myBindingSource2.DataSource = firstpunktausbildung; comboBox2.DataSource = myBindingSource2; comboBox2.DisplayMember = "Value"; comboBox2.ValueMember = "Key";
//Compobox4 füllen (Verbindungsmittel) Dictionary<string, string> firstpunktausbildungart; firstpunktausbildungart = new Dictionary<string, string>(); firstpunktausbildungart.Add("0", "Nägel"); firstpunktausbildungart.Add("1", "Dübel"); firstpunktausbildungart.Add("2", "Bolzen"); BindingSource myBindingSource3 = new BindingSource(); myBindingSource3.DataSource = firstpunktausbildungart; comboBox4.DataSource = myBindingSource3; comboBox4.DisplayMember = "Value"; comboBox4.ValueMember = "Key"; } |
Und so werte ich die comboBox1 aus:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54:
| private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //Pfette if (comboBox1.SelectedIndex==2) { this.label54.Text = "Pfettenabmessungen"; this.label53.Text = "Pfetten Höhe"; this.label52.Text = "Pfetten Breite"; //Textbox für t freigeben this.textBox17.Enabled = true; //Firstausbildungstyp aktivieren this.comboBox2.Enabled = true; this.comboBox4.Enabled = true; this.comboBox5.Enabled = true; this.comboBox6.Enabled = true; this.comboBox7.Enabled = true; this.comboBox8.Enabled = true; this.checkBox1.Enabled = true; } //Latte else if (comboBox1.SelectedIndex==0) { this.label54.Text = "Lattenabmessungen"; this.label53.Text = "Latte Höhe"; this.label52.Text = "Latte Breite"; //Textbox für t sperren this.textBox17.Enabled = false; //Firstausbildungstyp aktivieren this.comboBox2.Enabled = true; this.comboBox4.Enabled = true; this.comboBox5.Enabled = true; this.comboBox6.Enabled = true; this.comboBox7.Enabled = true; this.comboBox8.Enabled = true; this.checkBox1.Enabled = true; } //Bohle else if (comboBox1.SelectedIndex==1) { this.label54.Text = "Bohlenabmessungen"; this.label53.Text = "Bohlen Höhe"; this.label52.Text = "Bohlen Breite"; //Textbox für t sperren this.textBox17.Enabled = false; //Firstausbildungstyp sperren this.comboBox2.Enabled = false; this.comboBox4.Enabled = false; this.comboBox5.Enabled = false; this.comboBox6.Enabled = false; this.comboBox7.Enabled = false; this.comboBox8.Enabled = false; this.checkBox1.Enabled = false; } } |
Dieser Teil funktioniert auch. Daher habe ich die Auswertung der comboBox2 analog versuch. Leider ohne Erfolg. Viellicht könnt ihr mir ja helfen.
Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
| private void comboBox2_Changed(object sender, EventArgs e) { MessageBox.Show("er hat gemerkt das sich bei 2 was ändert "); //Versuch um zu Prüfen, ob bei Änderung was passiert, leider ohne Erfolg if (comboBox2.SelectedIndex == 0) { this.comboBox4.Enabled = false; this.comboBox5.Enabled = false; this.comboBox6.Enabled = false; this.comboBox7.Enabled = false; this.comboBox8.Enabled = false; this.checkBox1.Enabled = false; } else if (this.comboBox2.SelectedIndex == 1) { this.comboBox4.Enabled = true; this.comboBox5.Enabled = true; this.comboBox6.Enabled = true; this.comboBox7.Enabled = true; this.comboBox8.Enabled = true; this.checkBox1.Enabled = true; } } |
Wäre sehr dankbar für ein paar Tipps.
Vielen Dank schon mal
Mfg
Moderiert von
Th69: Titel sowie Codeformatierung leicht überarbeitet.