标签:style blog io color ar os for sp 数据
private void btnAdd_Click(object sender, EventArgs e) { ListBox.SelectedObjectCollection selectObj = this.listLeft.SelectedItems; foreach (DataRowView item in selectObj) { Sta sta = new Sta(); sta.STCD = int.Parse(item.Row.ItemArray[0].ToString()); sta.Name = item.Row.ItemArray[1].ToString(); list.Add(sta); } BindingSource bs = new BindingSource(); bs.DataSource = list; this.listRight.DataSource = bs; this.listRight.DisplayMember = "NAME"; this.listRight.ValueMember = "STCD"; }
private void btnAdd_Click(object sender, EventArgs e) { ListBox.SelectedObjectCollection selectObj = this.listLeft.SelectedItems; foreach (DataRowView item in selectObj) { bool b = true; //要查看listright是否已经有了这一项,有就不添加 foreach (Model.Sta rightItem in this.listRight.Items) { if (rightItem.Name == item.Row.ItemArray[1].ToString()) { b = false; } } if (b) { Sta sta = new Sta(); sta.STCD = int.Parse(item.Row.ItemArray[0].ToString()); sta.Name = item.Row.ItemArray[1].ToString(); list.Add(sta); } } BindingSource bs = new BindingSource(); bs.DataSource = list; this.listRight.DataSource = bs; this.listRight.DisplayMember = "NAME"; this.listRight.ValueMember = "STCD"; }
#region 添加右边listboxitems ListBox.SelectedObjectCollection selectObj = this.listLeft.SelectedItems; foreach (Model.Sta item in selectObj) { bool b = true; //要查看listright是否已经有了这一项,有就不添加 foreach (Model.Sta rightItem in this.listRight.Items) { if (rightItem.Name == item.Name) { b = false; } } if (b) { Sta sta = new Sta(); sta.STCD = item.STCD; sta.Name = item.Name; this.listRight.Items.Add(sta); } } this.listRight.DisplayMember = "NAME"; this.listRight.ValueMember = "STCD"; #endregion //删除左边已经添加的item //1-2:把选中的item移除 int icount = listLeft.SelectedItems.Count; for (int i = 0; i < icount; i++) { this.listLeft.Items.Remove(listLeft.SelectedItems[icount - 1 - i]); }
标签:style blog io color ar os for sp 数据
原文地址:http://www.cnblogs.com/fucker/p/4076151.html