Click here to Skip to main content
Click here to Skip to main content

Remove multiple items from ListBox

By , 14 May 2010
 
public static void RemoveSelected(this ListControl source)
{
    foreach (var item in source.Items.Cast<ListItem>().Where(li => li.Selected).ToList())
        source.Items.Remove(item);
}
 
protected void btnRemove_Click(object sender, EventArgs e)
{
    lstCity.RemoveSelected();
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Partenon
Web Developer
Sweden Sweden
Software developer

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralReason for my vote of 5 i like most your this post thanksmemberganpati120-Dec-11 20:49 
Generalforeach (var item in source.Items.Cast&lt;ListItem&gt;().Whe...memberrajekavi29-Jun-11 3:58 
General memberrajekavi29-Jun-11 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130619.1 | Last Updated 14 May 2010
Article Copyright 2010 by Partenon
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid