Vaibhav Aggarwal
Vaibhav Aggarwal

Reputation: 49

C# list box new lines

I am trying to print new lines on a list box in windows form, but /n or /r/n is not working to print in different lines. It all prints as a single element

Upvotes: 0

Views: 8885

Answers (2)

Eliahu Gordon
Eliahu Gordon

Reputation: 21

You can use Regex.Split to split up your string to multiple lines like this:

foreach (string s in Regex.Split(TheStringContainigTheNewLines, "\n"))
    lbMyListBox.Items.Add(s); 

Upvotes: 2

Davide Piras
Davide Piras

Reputation: 44595

.NET windows forms standard listbox does not support multi line items.

to get what you describe you either use another control or customize the ListBox to work differently.

have a look at this link: An editable multi-line listbox for .NET for an example

also have a look at this other one, still about extending controls with Owner Drawn approach: Owner Drawn Controls - Extendable ListBox

Upvotes: 4

Related Questions