2

I'm trying to put data with linebreakes to one item in listbox

how I make a breaklines in this command?

listBox1.Items.Add("");

or other command

example to what I mean

thanks

stuartd
  • 70,509
  • 14
  • 132
  • 163
Nadav
  • 65
  • 9
  • tried doesnt worked – Nadav Mar 23 '17 at 12:22
  • 1
    Possible duplicate of [Can ListBox items span multiple lines? C#](http://stackoverflow.com/questions/18360871/can-listbox-items-span-multiple-lines-c-sharp) – Ofir Winegarten Mar 23 '17 at 12:24
  • Use WPF control. It can be used in Winforms too. – Fabio Mar 23 '17 at 12:25
  • Possible duplicate of [Multi-line list items on WinForms ListBox control?](http://stackoverflow.com/questions/9532368/multi-line-list-items-on-winforms-listbox-control) – Massimiliano Kraus Mar 23 '17 at 12:42
  • This is sort of a case of "listbox abuse". You'd be better served making a custom control with labels and creating a list of those controls. This also allows you to do neat things like hide the details of an item unless you click an "expand" arrow. – CDove Mar 23 '17 at 12:44
  • You right, but I want to make that the listbox will autoroll (like marquee), so it doesnt suitable to my case – Nadav Mar 23 '17 at 13:23

1 Answers1

0
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        var product = new Product
        {
            ProductName = "Some name",
            Id = "123X",
            Size = "Big",
            OutOfStock = "true"
        };

        var itm = new ListBoxItem {Content = $"Product Name: {product.ProductName} {Environment.NewLine}" +
                                             $"ID: {product.Id} {Environment.NewLine}" +
                                             $"Size: {product.Size} {Environment.NewLine}" +
                                             $"Out of stock {product.OutOfStock}"
        };

        listBox.Items.Add(itm);
    }
}

public class Product
{
    public string ProductName { get; set; }
    public string Id { get; set; }
    public string Size { get; set; }
    public string OutOfStock { get; set; }
}