C# ListBox中的Item拖拽代码分享
2018-03-26 08:50
866 查看
我们先来看下运行效果图
Form1.cs代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Collections; namespace MoveItem { public partial class Form1 : Form { public Form1() { InitializeComponent(); } ArrayList list = new ArrayList(); private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { for (int i = 1; i <= 10; i++) { list.Add(i); string s = i.ToString(); listBox1.Items.Add(s); } } private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { //单选,无法实现多选 //string str = this.listBox1.Text.Trim().ToString(); //if (listBox1.Items.Contains(str)) //{ // listBox1.Items.Remove(str); // listBox2.Items.Add(str); //} for (int i=0;i<listBox1.SelectedIndices.Count;i++) { listBox2.Items.Add(listBox1.Items[listBox1.SelectedIndices[i]]); listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]); i--; } } private void button2_Click(object sender, EventArgs e) { for (int i = 0; i < listBox2.SelectedIndices.Count; i++) { listBox1.Items.Add(listBox2.Items[listBox2.SelectedIndices[i]]); listBox2.Items.RemoveAt(listBox2.SelectedIndices[i]); i--; } } private void button3_Click(object sender, EventArgs e) { listBox2.Items.AddRange(listBox1.Items); listBox1.Items.Clear(); } private void button4_Click(object sender, EventArgs e) { listBox1.Items.AddRange(listBox2.Items); listBox2.Items.Clear(); } } }
大家可以测试运行下,有其他问题可以在下方的留言区讨论,感谢大家对脚本之家的支持。
您可能感兴趣的文章:
相关文章推荐
- Android 拖拽效果实现代码分享 - ORIETech
- 代码分享 鼠标拖拽div
- 微信小程序之拖拽排序(代码分享)
- js实现图片放大和拖拽特效代码分享
- js实现图片放大和拖拽特效代码分享
- android ItemTouchHelper实现可拖拽和侧滑的列表的示例代码
- C#强力粉碎文件代码分享,升级中用到
- 简单的 Android 社会化分享登录库,一行代码搞定
- 分享用于学习C++音频处理的代码示例
- Python实现爬取知乎神回复简单爬虫代码分享
- 用js读、写、删除Cookie代码分享及详细注释说明
- 【分享】一些经典的C/C++语言基础算法及代码(二)
- GRID拖拽行的实例代码
- Python随机生成一个6位的验证码代码分享
- javascript强大的日期函数代码分享
- VC直接发送WM_DROPFILES消息,模拟拖拽动作代码
- PHP中实现crontab代码分享
- 分享代码
- 分享:世界机场代码(ICAO)[带经纬度]
- 也发个JavaScript 拖拽布局的代码. 带编辑功能..