关于两个ListBox的传值与删除item问题
目的就是把选种listBox1的Items插入到listbox2,并删除选择listBox1的items
listBox1可以多选.
以下代码执行有错误,应该怎样改进才能实现上述功能呢?
当foreach执行第二编就出错了.
private void Button1_Click(object sender, System.EventArgs e)
{
foreach( ListItem ls in this.ListBox1.Items )
{
if( ls.Selected )
{
ListItem lstItem = new ListItem();
lstItem.Text = ls.Text;
lstItem.Value = ls.Value;
this.ListBox2.Items.Add( lstItem );
this.ListBox1.Items.Remove( ls );
//this.ListBox2.Items.
}
}
}
listBox1可以多选.
以下代码执行有错误,应该怎样改进才能实现上述功能呢?
当foreach执行第二编就出错了.
private void Button1_Click(object sender, System.EventArgs e)
{
foreach( ListItem ls in this.ListBox1.Items )
{
if( ls.Selected )
{
ListItem lstItem = new ListItem();
lstItem.Text = ls.Text;
lstItem.Value = ls.Value;
this.ListBox2.Items.Add( lstItem );
this.ListBox1.Items.Remove( ls );
//this.ListBox2.Items.
}
}
}
...全文
相关推荐
C#实现让ListBox适应最大Item宽度的方法
将测量得到的最大宽度加上适当的边距,然后设置给ListBox的`Width`属性。通过这种方法,我们可以确保ListBox在显示内容时始终保持良好的可视性,避免因为Item过长而无法完全显示的问题。
asp.net中ListBox 绑定多个选项为选中及删除实现方法
)) { item.Selected = true; } }}```在上述代码中,我们首先确定了哪些项的值需要被选中,然后遍历ListBox中的所有选项,根据条件判断哪些选项应该被选中,并设置其Selected
WPF实现让ListBox的Item飞入飞出特效
通过设置`From`和`To`属性来指定动画的起始和结束位置,配合`Duration`属性设定动画的时长,可以让Item在两个位置间平滑地移动。4.
listBox控件用法(示例)
- `SelectedValue`: 如果项与数据源关联,此属性返回或设置选中项的值。
实现ListBox控件与ListBox控件交换数据
这个主题主要涉及如何在两个ListBox控件之间有效地移动、添加或删除数据,以满足用户的需求。以下是对这一主题的详细探讨:1.


