简体   繁体   English

C# 检查列表框中的选定项是否在一个序列中

[英]C# check if selected items in a listbox are in a sequence

我有一个包含 29 个项目的列表框,我想检查用户是否按顺序选择了项目,例如他是否选择 (1,2,3,4) 一个消息框会显示他选择了 (1 到 4) 和如果他选择 (1,3,5) 消息框会说他选择了 (1,3 和 5)。

I see what you want to do.我明白你想做什么。 The first approach would be to know what he selected like this :第一种方法是知道他像这样选择了什么

for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
  MessageBox.Show("You selected the item " + listBox1.SelectedItems[i] + " with index " + i.ToString());
}

And then, as saw in the MessageBox, get the index which I think is what you want.然后,如 MessageBox 中所见,获取我认为是您想要的索引 If you want to list all selected items in one MessageBox , just let the user select the items he want, make a button that will say what items he selected in total .如果您想在一个 MessageBox 中列出所有选定的项目,只需让用户选择他想要的项目,制作一个按钮,显示他总共选择哪些项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM