0
private void Form1_Load(object sender, EventArgs e)
{
    int x = 0, y = 0;
    var list = GetFilterItems().Select(g => g.GroupID).Distinct();
    ListBox lst;
    foreach (var item in list)
    {
        lst  = new ListBox();
        lst.Size = new Size(161, 82);
        lst.Name = item.ToString();
        lst.SelectionMode = SelectionMode.MultiExtended;

        lst.Location = new Point(x,y+25);

        pnlFilters.Controls.Add(lst);
        lst.Click += new EventHandler(lst_Click);
        x += lst.Width+5;
    }             
}

void lst_Click(object sender, EventArgs e)
{           
    ItemChanged(sender);
}

private void ItemChanged(object sender)
{
    // Get the selected ListBox
    ListBox selectedListViewControl = (ListBox)sender;

    // Get the ListBox's items
    List<FilterItem> currentFilterItems = selectedListViewControl.Items.Cast<FilterItem>().ToList();

    // Get the ListBox's selected items
    List<FilterItem> selectedFilterItems = selectedListViewControl.SelectedItems.Cast<FilterItem>().ToList();
}

上記のコードでは、リストボックスから複数のアイテムを選択しても、選択されたアイテムは1つしかありませんリストボックスから複数のアイテムを取得する方法

4

1 に答える 1

0

1 つのリストボックスを作成し、すべての項目をこの 1 つのリストボックスに追加するだけです

その後、複数選択が機能します

于 2012-12-21T14:05:01.473 に答える