c#中如何获取listbox的多选的值(实际值ValueMembet)
2016-04-13
展开全部
/// <summary>
/// 取ListBox选中项id
/// </summary>
/// <returns>id数组</returns>
private int[] GetIDS()
{
int[] id = new int[listBox1.SelectedIndices.Count];
for (int i = 0; i < listBox1.SelectedIndices.Count; i++)
{
id[i] = (int)listBox1.SelectedIndices[i];
}
return id;
} GetIDS()取出来的是选中项ID数组,你可以用循环遍历出来:int[] id=GetIDS();
textBox1.Clear();
for (int i = 0; i<id.Length; i++)
{
textBox1.Text += id[i].ToString();
}
/// 取ListBox选中项id
/// </summary>
/// <returns>id数组</returns>
private int[] GetIDS()
{
int[] id = new int[listBox1.SelectedIndices.Count];
for (int i = 0; i < listBox1.SelectedIndices.Count; i++)
{
id[i] = (int)listBox1.SelectedIndices[i];
}
return id;
} GetIDS()取出来的是选中项ID数组,你可以用循环遍历出来:int[] id=GetIDS();
textBox1.Clear();
for (int i = 0; i<id.Length; i++)
{
textBox1.Text += id[i].ToString();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询