码迷,mamicode.com
首页 > 其他好文 > 详细

ListBox

时间:2014-12-09 17:20:26      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:ar   os   sp   for   div   bs   ad   ef   as   

//左到右

private void btnLeftToRight_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItems != null)
{
foreach (var item in listBox1.SelectedItems)
{
listBox2.Items.Add(item.ToString());
}

for (int i = 0; i < listBox1.SelectedIndices.Count; i++)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]);
i--;
}
}
}

 

//右到左

private void btnRightToLeft_Click(object sender, EventArgs e)
{
if (listBox2.SelectedItems != null)
{
foreach (var item in listBox2.SelectedItems)
{
listBox1.Items.Add(item.ToString());
}

for (int i = 0; i < listBox2.SelectedIndices.Count; i++)
{
listBox2.Items.RemoveAt(listBox2.SelectedIndices[i]);
i--;
}
}
}

 

追问:

foreach (var item in listBox1.SelectedItems)
{
listBox2.Items.Add(item.ToString());
}

for (int i = 0; i < listBox1.SelectedIndices.Count; i++)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]);
i--;
}

ListBox

标签:ar   os   sp   for   div   bs   ad   ef   as   

原文地址:http://www.cnblogs.com/ZhangYuLIng/p/4153572.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!