Autor Beitrag
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4805
Erhaltene Danke: 1061

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 12.03.08 13:03 
Wenn ich eine MultiSelection-Listbox mit einer Datenquelle verbunden habe:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
System.Windows.Forms.ListBox lbPlatforms;

lbPlatforms.DataSource = Platform.SortByName(Platform.All);
lbPlatforms.SelectionMode = SelectionMode.MultiExtended; // oder MultiSimple
lbPlatforms.FormattingEnabled = true;
lbPlatforms.DisplayMember = "Name";
lbPlatforms.ValueMember = "Id";

Wie komme ich jetzt an die Values aller selektierten Einträge, d.h. ich benötige jetzt die Ids der Plattformen???
Mittels "lbPlatforms.SelectedValue" komme ich ja nur an einen Eintrag (bei einer SingleSelection-Listbox).
Th69 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4805
Erhaltene Danke: 1061

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 17.03.08 11:24 
Ok, habe es jetzt selber hinbekommen:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
foreach(int nIdx in lbPlatforms.SelectedIndices)
{
    Platform platform = lbPlatforms.Items[nIdx] as Platform;
    if(platform != null)
    {
        int nPlatformId = platform.Id;
    }
}

bzw. wenn man weiß, daß nur Objekte einer Klasse enthalten sind:
ausblenden C#-Quelltext
1:
2:
3:
4:
foreach(Platform platform in lbPlatforms.SelectedItems)
{
    int nPlatformId = platform.Id;
}

Also genau so, als wenn man die Items mittels Add() bzw. AddRange() eingefügt hätte...