for(int i=0;i<this.listBox1.SelectedIndices.Count;i++)
{
MessageBox.Show(this.listBox1.Items[this.listBox1.SelectedIndices[i]].Text);
}
{
MessageBox.Show(this.listBox1.Items[this.listBox1.SelectedIndices[i]].Text);
}
{
System.Console.WriteLine(this.listBox1.SelectedItems[i]);
}
foreach ( int i in this.listBox1.SelectedIndices)
{
System.Console.WriteLine(this.listBox1.Items[i]);
}
MessageBox.Show(this.listBox1.SelectedItems[i].ToString());
{
System.Console.WriteLine(this.listBox1.Items[i]);
}
有英文耐心读一下
// Display a list of selected indices.
// The SelectedIndices property returns a SelectedIndexCollection
// object. Use its CopyTo method to copy the items to
// an array, so you can bind the list to a ListBox control.
int[] aIndices = new int[lstMultiSelect.SelectedIndices.Count];//lstMultiSelect为listbox
lstMultiSelect.SelectedIndices.CopyTo(aIndices, 0);
lstSelected.DataSource = aIndices;//lstSelected要显示的listbox