Autor Beitrag
DrHoas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Mo 11.04.11 22:38 
Hallo,

1. Ich möchte in einer ListBox mehrere Items per Code auswählen. Eins ist mit listbox.SelectedItem = ... kein Problem. Aber wie kann ich mehrere auswählen? SelectionMode="Multiple" hab ich natürlich drin.

2. Da die ListBox nicht fokusiert ist, wird die Auswahl nur in einem hellen grau dargestellt. Kann man das umstellen, sodass auch ohne Fokus das bekannte blau zu sehen ist?

Dank und Gruß

Philipp


Moderiert von user profile iconKha: Topic aus C# - Die Sprache verschoben am Di 12.04.2011 um 20:50
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Di 12.04.11 10:35 
Hallo,

bei einer MultiSelection-ListBox gibt es zum Auslesen die SelectedItems-Eigenschaft. Zum Setzen (bzw. Löschen) der Selection gibt es die Methode SetSelected(int index, bool value). Um vorher die gesamte Selection zu Löschen, kannst du SelectedItems.Clear() aufrufen.

Die Farbe wird von Windows vorgegeben. Nur durch Selberzeichnen (DrawMode = OwnerDrawFixed, DrawItem-Ereignis) kannst du selber die Farben etc. festlegen - ist aber etwas aufwendiger.
DrHoas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Di 12.04.11 15:12 
Die Methode SetSelected hatte ich auch im Netz gefunden. Bei mir gibt es die aber nicht. Woran liegt das?

Philipp
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Di 12.04.11 15:37 
Hallo,

benutzt du denn WinForms oder WPF?
DrHoas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Di 12.04.11 16:18 
WPF

Philipp
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Di 12.04.11 16:24 
Hallo nochmal,

dann hättest du besser auch gleich im WPF-Forum gepostet...

Es müßte aber einfach mittels SelectedItems.Add(...) funktionieren.
DrHoas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Di 12.04.11 16:55 
tut, danke!

Philipp