问题
how can I pass the items of listbox to richtextbox?. I have multiple items and I want it to display in the richtextbox. this items is like a receipt. it display the items along with its amount.
回答1:
This is just a way to do it, using LINQ
:
Dim Items As String() =
From s As String In ListBox1.Items
RichTextBox1.Text = String.Join(Environment.NewLine, Items)
回答2:
One of the problems doing this with a listbox, is that listboxes store the items as objects and uses the ToString method of each object to display a representation of that object.
Something like this should work:
RichTextBox1.Lines = (From o In ListBox1.Items
Let ostr = o.ToString
Select ostr).ToArray
This way if you use objects that can't be implicitly cast as string it will still work. Or, if you use custom objects all that's required is a ToString override in the class.
来源:https://stackoverflow.com/questions/22288852/passing-all-the-items-of-listbox-in-the-richtextbox