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 个选定项目 如何获取多个项目表单列表框