Wrox Programmer Forums
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2006, 09:26 AM
Registered User
 
Join Date: Jun 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rajvijaygarg
Default List Box

Dear Friends
We are using C# for our project and for If i use list Box and want to remove few items without using for loop , how can i do that because we want to add we can if we want to remove we are not able because i didn't any such fuctionality .can u please help me in this regards.



Vijay Garg
 
Old June 20th, 2006, 05:48 AM
Authorized User
 
Join Date: Apr 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can remove when item is selected:

index = this.listbox.SelectedIndex;
this.listbox.Items.Remove(index);

this should work

 
Old June 20th, 2006, 11:47 PM
Registered User
 
Join Date: Jun 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rajvijaygarg
Default

No Dera It will not work bcz as multiple selection will be thier then index will change every time and it will not work.

Vijay Garg
 
Old June 20th, 2006, 11:49 PM
Registered User
 
Join Date: Jun 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rajvijaygarg
Default

No Dear
 It will not work bcz as multiple selection will be thier then index will change every time and it will not work.

Vijay Garg

Vijay Garg
 
Old June 21st, 2006, 06:17 AM
Authorized User
 
Join Date: Apr 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well if you have multiselect maybe with a for...

for(int c=0;c<listBox1.Items.Count;c++)
{
    if(listBox1.Items[c].Selected)
         ListBox1.Items.Remove(ListBox1.Items[c]);
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.