值传、、、、、 两个LISTBOX控件,要求两个LISTBOX中的项可以左右移动,可单个移动也可多个移动。点击右移LISTBOX_1的值传到LISTBOX_2里。点左一样。 怎么实现呀 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 按钮事件! 添加list和删除list! private void button1_Click(object sender, EventArgs e) { if (this.listBox1.SelectedIndex > -1) { this.listBox2.Items.Add(listBox1.SelectedItem); this.listBox1.Items.Remove(listBox1.SelectedItem); } Set(); } private void button2_Click(object sender, EventArgs e) { if (this.listBox2.SelectedIndex > -1) { this.listBox1.Items.Add(listBox2.SelectedItem); this.listBox2.Items.Remove(listBox2.SelectedItem); } Set(); } private void Set() { this.button1.Enabled = this.listBox1.Items.Count>0 ? true : false; this.button2.Enabled = this.listBox2.Items.Count > 0 ? true : false; } 大体一致 //选择向右移: int Count = ListBox1.Items.Count; for (int Index = 0; Index < Count; Index++) { ListItem Item = ListBox1.Items[Index]; if (ListBox1.Items[Index].Selected == true) { ListBox1.Items.Remove(Item); ListBox2.Items.Add(Item); Count--; Index--; } } //选择向左移代码: int Count = ListBox2.Items.Count; for (int Index = 0; Index < Count; Index++) { ListItem Item = ListBox2.Items[Index]; if (ListBox2.Items[Index].Selected == true) { ListBox2.Items.Remove(Item); ListBox1.Items.Add(Item); Count--; Index--; } } 另外ListBox1需要首先赋值测试:<asp:ListBox ID="ListBox1" runat="server" Height="156px" Width="132px" SelectionMode="Multiple"> <asp:ListItem>轻音乐</asp:ListItem> <asp:ListItem>热门DJ</asp:ListItem> <asp:ListItem>伤感音乐专题</asp:ListItem></asp:ListBox>另外增加连个按钮:右移按钮: btnMoveRight,事件如上代码,左移按钮:btnMoveLeft 单个移动: 自己去删除和添加items就可以了;多个移动: 首先要实现选择多项,想怎么选自己去定义,然后把这些项逐一添加,最后删除原来的。具体代码楼上几位贴了不少,看看大概就可以了。 int Count = ListBox1.Items.Count; for (int Index = 0; Index < Count; Index++) { ListItem Item = ListBox1.Items[Index]; if (Item.Selected == true) { ListBox1.Items.Remove(Item); ListBox2.Items.Add(Item); Count--; Index--; } }同理就可以实现了 请教:C#如何通过LDAP协议获取AD帐号的名称 页面刷新问题asp.net 求助,正则表达式,在线等(急) 求教!!!!!!!!! 自己机器可以运行,服务器不行 erp中如何处置可能导致负数据的情况呢? 请教一个问题 TreeView节点提示问题. 跪求C#下如何实现自定义结构或类与BYTE数组之间的相互转换(即数据的打包与解包)? 关于winfrom程序访问web网页的问题,解决就结贴给分! asp.net html控件asp控件之间的关系 VS2005 安装 MapObjects
{
if (this.listBox1.SelectedIndex > -1)
{
this.listBox2.Items.Add(listBox1.SelectedItem);
this.listBox1.Items.Remove(listBox1.SelectedItem);
}
Set();
}
private void button2_Click(object sender, EventArgs e)
{
if (this.listBox2.SelectedIndex > -1)
{
this.listBox1.Items.Add(listBox2.SelectedItem);
this.listBox2.Items.Remove(listBox2.SelectedItem);
}
Set();
}
private void Set()
{
this.button1.Enabled = this.listBox1.Items.Count>0 ? true : false;
this.button2.Enabled = this.listBox2.Items.Count > 0 ? true : false;
}
大体一致
int Count = ListBox1.Items.Count; for (int Index = 0; Index < Count; Index++)
{
ListItem Item = ListBox1.Items[Index]; if (ListBox1.Items[Index].Selected == true)
{
ListBox1.Items.Remove(Item);
ListBox2.Items.Add(Item); Count--;
Index--;
}
}
//选择向左移代码:
int Count = ListBox2.Items.Count; for (int Index = 0; Index < Count; Index++)
{
ListItem Item = ListBox2.Items[Index]; if (ListBox2.Items[Index].Selected == true)
{
ListBox2.Items.Remove(Item);
ListBox1.Items.Add(Item); Count--;
Index--;
}
}
另外ListBox1需要首先赋值测试:
<asp:ListBox ID="ListBox1" runat="server" Height="156px" Width="132px" SelectionMode="Multiple">
<asp:ListItem>轻音乐</asp:ListItem>
<asp:ListItem>热门DJ</asp:ListItem>
<asp:ListItem>伤感音乐专题</asp:ListItem>
</asp:ListBox>另外增加连个按钮:右移按钮: btnMoveRight,事件如上代码,左移按钮:btnMoveLeft
自己去删除和添加items就可以了;
多个移动:
首先要实现选择多项,想怎么选自己去定义,然后把这些项逐一添加,最后删除原来的。具体代码楼上几位贴了不少,看看大概就可以了。
{
ListItem Item = ListBox1.Items[Index]; if (Item.Selected == true)
{
ListBox1.Items.Remove(Item);
ListBox2.Items.Add(Item); Count--;
Index--;
}
}同理就可以实现了