Autor Beitrag
ridderle
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Fr 01.08.08 14:07 
Hallo,
ich möchte mich mal versuchen ein kleines Programm zu schreiben, bei dem ich ein paar Werte über mehrere Combobox auswählen kann und ich dann mittels eines "berechnen"- Buttons ich die Summe der Werte der Combobox auf einem Textlabel ausgeben lassen kann.

Die grafische Oberfläche habe ich nun auch schon angelegt.
Nun ist meine Frage:

- wie kann ich die Werte, die in den Comboxboxen sind addieren?

ich denke die Idee ist ja so ok:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
       double summe = 0.0;
                for (int no = 0; no < 7; no++)
                {
                    summe = summe + ComboBox(no).Item;
                }
                 return summe;


aber das ComboBox(no) stimmt ja nicht, wie geht das?


Zuletzt bearbeitet von ridderle am Fr 01.08.08 14:34, insgesamt 1-mal bearbeitet
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 01.08.08 14:49 
Die Idee ist so okay, obwohl man eine Combobox normalerweise nur zur Anzeige von Daten verwendet und nicht zur Datenhaltung. Aber ist für jetzt wahrscheinlich einfacher, es so zu lassen und sich auf das eigentliche Problem zu beschränken.

Für die Zukunft: Gib bitte die Fehlermeldung mit an, wenn etwas nicht funktioniert.

Die Lösung Deines Problem ist einfach:
Du musst überlegen, welchen Typ ein Combobox-Item hat und welchen Typ Du brauchst.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
ridderle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Fr 01.08.08 17:27 
also bisher hat es gar keinen datentyp

ausblenden C#-Quelltext
1:
2:
3:
4:
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }



im Formdesigner:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
        private System.Windows.Forms.ComboBox comboBox1;
        private System.Windows.Forms.ComboBox comboBox2;
        private System.Windows.Forms.ComboBox comboBox3;
        private System.Windows.Forms.ComboBox comboBox4;
        private System.Windows.Forms.ComboBox comboBox5;
        private System.Windows.Forms.ComboBox comboBox6;


daran hängts grad bei mir...

Ich will natürlich einen double.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 01.08.08 18:17 
user profile iconridderle hat folgendes geschrieben:
also bisher hat es gar keinen datentyp

Wenn was drin steht, hat es auch einen Typ.

user profile iconridderle hat folgendes geschrieben:
ausblenden C#-Quelltext
1:
2:
3:
4:
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

Was soll mir das zeigen? Das Changed-Ereignis ist leer - und?

user profile iconridderle hat folgendes geschrieben:
im Formdesigner:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
        private System.Windows.Forms.ComboBox comboBox1;
        private System.Windows.Forms.ComboBox comboBox2;
        private System.Windows.Forms.ComboBox comboBox3;
        private System.Windows.Forms.ComboBox comboBox4;
        private System.Windows.Forms.ComboBox comboBox5;
        private System.Windows.Forms.ComboBox comboBox6;


daran hängts grad bei mir...

Das hat nix mit Deinem Problem zu tun. Dass die Comboboxen vom Typ ComboBox ist, war irgendwie klar :roll:

user profile iconridderle hat folgendes geschrieben:
Ich will natürlich einen double.

Und was machst Du, wenn Du einen Typen hast aber einen anderen ahben willst?


Nur als Hinweis: Ich werde sicherlich nicht nochmal sowas wie hier mitmachen! Entweder Du fängst an, zu zeigen, dass Du seit dem Grundlagen gebüffelt hast (und bisher sieht es nicht so aus), oder ich höre auf zu antworten.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
ridderle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Fr 01.08.08 18:32 
ja dann caste ich.

wo sollte was drin stehen?
Ich sehe leider keinen double in meinem Quellcode...
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 02.08.08 12:09 
Du hast doch Zahlen in Deinen Comboboxen stehen. Wie hast Du die da reinbekommen?

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".