1
votes

I have three listboxes. the selected items from one listbox(lst1) should be populated in another listbox(lst2) on click of add button and accordingly the third listbox(lst3) needs to be populated with values from db as per the selected values in lst2. theres no selecteditems property i m using ms visual studio2005 similar logic need to be used on click of remove button

2
Can you explain it a little more?Nelson Reis

2 Answers

0
votes
public static class Extensions
{
    public static IEnumerable<ListItem> GetSelectedItems(
           this ListItemCollection items)
    {
        return items.OfType<ListItem>().Where(item => item.Selected);
    }


}
On button click
------------------
var selected = lstFirst.Items.GetSelectedItems();

    foreach (var li in selected)
    {
        if (!lstSecond.Items.Contains(li))
        {
            ListItem newItem = new ListItem(li.Text, li.Value);
            lstSecond.Items.Add(newItem);
        }
    }
-2
votes

someting and somethingelse are listboxes

    For Each Item As ListItem In something.Items
        If Item.Selected Then
            somethingelse.Items.Add(Item)
        End If
    Next