Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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'.

Posted

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);
}

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...