C# removing items from listbox

后端 未结 16 2250
礼貌的吻别
礼貌的吻别 2020-12-02 00:12

I have a listbox being populated from a SQLDATA pull, and it pulls down some columns that i dont want like OBJECT_dfj, OBJECT_daskd. The key is all of these being with OBJE

16条回答
  •  失恋的感觉
    2020-12-02 00:18

    protected void lbAddtoDestination_Click(object sender, EventArgs e)
            {
                AddRemoveItemsListBox(lstSourceSkills, lstDestinationSkills);
            }
            protected void lbRemovefromDestination_Click(object sender, EventArgs e)
            {
                AddRemoveItemsListBox(lstDestinationSkills, lstSourceSkills);
            }
            private void AddRemoveItemsListBox(ListBox source, ListBox destination)
            {
                List toBeRemoved = new List();
                foreach (ListItem item in source.Items)
                {
                    if (item.Selected)
                    {
                        toBeRemoved.Add(item);
                        destination.Items.Add(item);
                    }
                }
                foreach (ListItem item in toBeRemoved) source.Items.Remove(item);
            }
    

提交回复
热议问题