How do I move all items in a listbox to another listbox

Discussion in 'ASP .Net' started by kent, May 2, 2004.

  1. kent

    kent Guest

    Hi All,

    On my form, I have 2 listboxes that get populated with the correct items.
    I have 4 buttons between the 2 boxes. The first 2 buttons are used to move
    the selected item
    back and forth between the boxes. That works fine.

    The last 2 are used to move all the listbox items (whether they're selected
    or not) that are in 1 box over to the other box.
    After the move, I want the other box to be empty. I am calling clear() and
    that works fine.
    I am having trouble here and need help.

    I have tried things like:
    listbox1.items.addRange(listbox2.items)
    listbox2.items.clear()

    I have tried a couple of other things with no success.
    I'm sort of a newbie, but I should be able to do this and I'm probably
    making it much harder than it has to be.
    Any help on how to do this would be greatly appreciated.

    Remove the 'nospam' for email or send to
    kent, May 2, 2004
    #1
    1. Advertising

  2. Try something list this (untested)

    foreach(Listitem li in lstSrc)
    {
    lstDest.Items.Add( new ListItem(li.Text,Li.Value));
    lstDest.Items.Remove(li);
    }
    "kent" <> wrote in message
    news:...
    > Hi All,
    >
    > On my form, I have 2 listboxes that get populated with the correct items.
    > I have 4 buttons between the 2 boxes. The first 2 buttons are used to

    move
    > the selected item
    > back and forth between the boxes. That works fine.
    >
    > The last 2 are used to move all the listbox items (whether they're

    selected
    > or not) that are in 1 box over to the other box.
    > After the move, I want the other box to be empty. I am calling clear() and
    > that works fine.
    > I am having trouble here and need help.
    >
    > I have tried things like:
    > listbox1.items.addRange(listbox2.items)
    > listbox2.items.clear()
    >
    > I have tried a couple of other things with no success.
    > I'm sort of a newbie, but I should be able to do this and I'm probably
    > making it much harder than it has to be.
    > Any help on how to do this would be greatly appreciated.
    >
    > Remove the 'nospam' for email or send to
    >
    >
    Andrew de la Harpe, May 3, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K B
    Replies:
    2
    Views:
    667
  2. bogdan
    Replies:
    2
    Views:
    894
    bogdan
    Apr 28, 2008
  3. divya
    Replies:
    1
    Views:
    1,086
    Munna
    May 28, 2008
  4. Jocke

    Move items from listbox and datagrid

    Jocke, Sep 29, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    278
    Jocke
    Sep 29, 2006
  5. vijay
    Replies:
    2
    Views:
    96
    vijay
    Apr 17, 2006
Loading...

Share This Page