SIMIN Posted May 6, 2008 Posted May 6, 2008 Hi, A component I use needs a collection to be added to it. I get a list from user in a multi line text box. So how can I add it? The list is multi line but is string and object needs collection. So when I use this: ThirdPartyObject.List.AddRange(ListTextBoxX.Text) Warning 1 Runtime errors might occur when converting 'String' to 'System.Collections.ICollection'. Quote
Administrators PlausiblyDamp Posted May 6, 2008 Administrators Posted May 6, 2008 You could just pass ListTextBoxX.Lines rather than .Text to the method. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted May 6, 2008 Posted May 6, 2008 In your case PD's idea to use the .Lines property is probably ideal. If for some reason you have similar data; but not in a TextBox control, you could try code like the following: // some delimited string String text = "Some Text, Line Two, Line Three"; // split text by delim save array result // define this as an array (the code tags are making my square brakets show up wrong) String sItems = text.Split(','); // add each item to the list foreach (String item in sItems) { If(item != String.Empty) ThirdPartyObject.List.Add(item); } Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.