private void buttonLoeschen_Click(object sender, EventArgs e) { //int localSelected = listBoxGarageAutos.SelectedIndex; //listBoxGarageAutos.Items.RemoveAt(localSelected); strucAuto localStrucAutoSelected = new strucAuto(); localStrucAutoSelected = (strucAuto)listBoxGarageAutos.SelectedItem; listBoxGarageAutos.Items.Remove(localStrucAutoSelected); }
//Hinzufügen der Liste zur Listbox private void addListToListbox(strucAuto lscAuto) { listBoxGarageAutos.Items.Clear(); listAuto.Add(lscAuto); foreach (strucAuto localstrucAuto in listAuto) { listBoxGarageAutos.Items.Add(localstrucAuto); } }
private void showSelectedItem() { strucAuto localScAuto = (strucAuto)listBoxGarageAutos.SelectedItem; textBoxModell.Text = localScAuto.Modell; textBoxBaujahr.Text = Convert.ToString(localScAuto.Baujahr); textBoxFarbe.Text = localScAuto.Farbe; textBoxKaufpreis.Text = Convert.ToString(localScAuto.Kaufpreis); textBoxMarke.Text = localScAuto.Marke; textBoxSpitzname.Text = localScAuto.Spitzname; }
// Methode zum hinzufügen eines strucAuto zur Liste private strucAuto addItemToList() { //Anlegen der Variablen strucAuto scLocalAuto = new strucAuto(); int intParsedValue; double dbParsedValue; scLocalAuto.Marke = textBoxMarke.Text; scLocalAuto.Modell = textBoxModell.Text; scLocalAuto.Farbe = textBoxFarbe.Text; //Prüfen ob ein Spitzname vorhanden if (textBoxSpitzname.Text.Length > 0) { scLocalAuto.Spitzname = textBoxSpitzname.Text; } // Generischer Spitzname der in der Liste angezeigt wird, sofern keiner eingegeben wurde else { scLocalAuto.Spitzname = "Auto " + (listBoxGarageAutos.Items.Count + 1); } // Testen ob Eingabe korrekt // Fall wenn korrekt if (int.TryParse(textBoxBaujahr.Text, out intParsedValue)) { scLocalAuto.Baujahr = Convert.ToInt32(textBoxBaujahr.Text); } // Fall wenn KEINE Angabe gemacht wurde else if (textBoxBaujahr == null || !int.TryParse(textBoxBaujahr.Text, out intParsedValue)) { scLocalAuto.Baujahr = 0; } // Fall wenn EIngabe falsch bspw. Buchstabe if (textBoxBaujahr.Text.Length > 0 && !int.TryParse(textBoxBaujahr.Text, out intParsedValue)) { MessageBox.Show("Ungültige Jahreszahl!\r\nBitte Aktualisieren!"); } // Selbe für den Kaufpreis if (double.TryParse(textBoxKaufpreis.Text, out dbParsedValue)) { scLocalAuto.Kaufpreis = Convert.ToDouble(textBoxKaufpreis.Text); } else if (textBoxKaufpreis == null || !double.TryParse(textBoxKaufpreis.Text, out dbParsedValue)) { scLocalAuto.Kaufpreis = 0; } if (textBoxKaufpreis.Text.Length > 0 && !double.TryParse(textBoxKaufpreis.Text, out dbParsedValue)) { MessageBox.Show("Ungültiger Kaufpreis!\r\nBitte Aktualisieren!"); } return(scLocalAuto); }