Autor Beitrag
highlander78
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Mo 17.09.07 13:44 
Hallo erstmal,

bin totaler Anfänger in C# und benötige einen Tip wie ich einen Wert aus einer "listBox" als einstellung für einen Port übernehme.

Ich habe ein Einfaches Programm erstellt dass bei mir auf einen fest eingestellten UDP Port Daten empfängt und in einer listBox ausgibt,das funktioniert ja auch.


Also ich gehe so vor :


listBox2.ItemsAdd.("600"); ---> in meiner listBox wird als Defaultwert der Port "600" eingestellt


so baue ich die verbindung auf:

listener = new UdpClient(hier sollte der Port aus der listBox übernomen werden);
groupEP = new IPEndPoint(IPAdress.Any,hier sollte der Port aus der listBox übernomen werden);


ist für euch bestimmt total einfach , aber ich zerbreche mir den Kopf seit 3 Tagen :-(
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Mo 17.09.07 14:47 
Also ich persönlich würde ja zum auswählen eine Combobox bevorzugen, aber egal.

Gilt für beide: Schau dir doch mal die Eigenschaften SelectedItem bzw. SelectedText an,
das wird dir weiterhelfen :)
highlander78 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Mo 17.09.07 16:37 
Hättest du vielleicht ein Beispiel für mich , ich bekomme hier schon Kopfschmerzen .
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Mo 17.09.07 17:20 
Klar:

ausblenden C#-Quelltext
1:
2:
string s = listBox1.SelectedItem.ToString();
string s2 = comboBox1.Text; // Das ist noch besser geeignet, geht aber nur für combobox

Jetzt musst du nur noch die Strings in Integer umwandeln. Das macht man zum
Beispiel mit int.Parse(string s).

Aus diesen Dingen sollte sich was zusammenbasteln lassen.

Wichtig:
Wenn bei SelectedItem kein Element ausgewählt ist, dann wird ein
Fehler geworfen, deshalb vorher noch prüfen ob überhaupt eines gewählt ist:
ausblenden C#-Quelltext
1:
2:
if (listBox1.SelectedItem != null)
/* ... */
highlander78 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Di 18.09.07 19:09 
danke

Hat mir sehr geholfen , habe es mit NumericUpDown gelöst, da ich so wie so nur eine Zahl als einstellwert brauche eignete es sich ganz gut.