Question

In my web application , I am having 2 List box as "MenuBox" and "UpdatedBox". The MenuBox items were populated from Database using Dataset. Now If I select a Item in MenuBox and Click "Move" button, the selected Item has to be copied to "UpdatedBox".... Can any one tell me how to achieve this ?

Was it helpful?

Solution 2

Hey Try this one this is tested code.

if (ListBox1.SelectedIndex > -1)
        {
            ListBox2.Items.Add(ListBox1.SelectedItem);
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);
            ListBox2.ClearSelection();
        }

Hope it helps you

OTHER TIPS

ListBox SelectionMode can be set single or multiple, in both cases below code will work

int[] selection = MenuBox.GetSelectedIndices();
while (selection.Length >0)
{
    UpdatedBox.Items.Add(MenuBox.Items[selection[0]].ToString());
    MenuBox.Items.RemoveAt(selection[0]);
    selection = MenuBox.GetSelectedIndices();
}
ListBox2.Items.Add(ListBox1.SelectedItem);

Try this

 while(ListBox1.Items.Count!=0)
 {
    for(int i=0;i<ListBox1.Items.Count;i++)
    {
        ListBox2.Items.Add(ListBox1.Items[i]);
        ListBox1.Items.Remove(ListBox1.Items[i]);
    }
 }

You can do something like this.

UpdatedBox.Items.Add(MenuBox.SelectedItem);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top