PC Review


Reply
Thread Tools Rate Thread

add items to list<>

 
 
csharpula csharp
Guest
Posts: n/a
 
      27th Nov 2007
Hello,
I am trying to add SelectedItems from ListBox to List<string>. It seems
like it's not working,any idea how to do it?
Thank you!



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      27th Nov 2007
Assuming the items in the ListBox are strings, then just loop:

foreach (string item in lb.SelectedItems) {
list.Add(item);
}

The problem is that it doesn't know that each item is a string, since
it can be anything.

Marc

 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      27th Nov 2007
Note on .NET 3.5 /C# 3 you could use:

list.AddRange(listbox.SelectedIndices.Cast<string>());
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to retrieve listbox items on postback , items moved usingjavascript between 2 list boxes (source and target ) divya Microsoft ASP .NET 1 28th May 2008 06:27 AM
Qry a random list of n items per dept from all items in 63 depts =?Utf-8?B?T2J2aW91c2x5IG5vdCBhIHByb2dyYW1tZXIgOig= Microsoft Access Queries 1 29th Oct 2005 07:02 AM
Data Validation: items in one list relate to items in another Paul D. Simon Microsoft Excel Programming 1 4th Aug 2005 09:17 PM
named range, data validation: list non-selected items, and new added items KR Microsoft Excel Misc 1 24th Jun 2005 05:21 AM
Items in disabled items list - unknown excel addins causing probs =?Utf-8?B?UmljaA==?= Microsoft Excel Programming 4 16th May 2005 10:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:52 PM.