using System;
using System.Windows.Forms;
namespace listview控件应用
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form_Load);
this.btnMoseSinleTor.Click += new EventHandler(MoveList);
this.btnMoveAllToL.Click += new EventHandler(MoveList);
this.btnMoveAllToR.Click += new EventHandler(MoveList);
this.btnMoveSingleToL.Click += new EventHandler(MoveList);
}
private void BindData(ListView list)
{
list.Items.Add("西装");
list.Items.Add("西裤");
list.Items.Add("衬衣");
list.Items.Add("短裤");
list.Items.Add("皮带");
list.Items.Add("男鞋");
list.Items.Add("女鞋");
}
private void Form_Load(object sender, EventArgs e)
{
BindData(listView1);
}
private void MoveList(object sender, EventArgs e)
{
Button b = (Button)sender;
switch (b.Text)
{
case ">>"://全部右移
if(listView1.Items.Count>0)
foreach (ListViewItem item in listView1.Items)
{
ListViewItem nitem = (ListViewItem)item.Clone();
listView2.Items.Add(nitem);
listView1.Items.Remove(item);
}
break;
case ">"://单条右移
if (listView1.SelectedItems.Count > 0)
{
ListViewItem item = listView1.SelectedItems[0];
ListViewItem nitem = (ListViewItem)item.Clone();
listView2.Items.Add(nitem);
listView1.Items.Remove(item);
}
break;
case "<<"://全部左移
if(listView2.Items.Count>0)
foreach (ListViewItem item in listView2.Items)
{
ListViewItem nitem = (ListViewItem)item.Clone();
listView1.Items.Add(nitem);
listView2.Items.Remove(item);
}
break;
case "<"://单条左移
if (listView2.SelectedItems.Count > 0)
{
ListViewItem item = listView2.SelectedItems[0];
ListViewItem nitem = (ListViewItem)item.Clone();
listView1.Items.Add(nitem);
listView2.Items.Remove(item);
}
break;
}
}
}
}
ListView控件间的数据移动
最新推荐文章于 2019-06-12 19:03:15 发布