passing all the items of listbox in the richtextbox

牧云@^-^@ 提交于 2019-12-24 11:37:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!