2017-03-23 17 views
2

我想把换行数据放入列表框中的一个项目在列表框项目c中的多行#

我该如何在此命令中划破界线?

listBox1.Items.Add(""); 

或其他命令

example to what I mean

感谢

+0

试图犯规工作的[列表框的项目可以跨越多行 – Nadav

+1

可能的复制? C#](http://stackoverflow.com/questions/18360871/can-listbox-items-span-multiple-lines-c-sharp) –

+0

使用WPF控件。它也可以在Winforms中使用。 – Fabio

回答

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; } 
} 
+0

试过了,它不工作:( – Nadav

+0

它不工作了,但谢谢 – Nadav

+0

它不工作,因为** ListboxItem **是为wpf而不是windows窗体 – ger