在富文本框中传递列表框的所有项目 [英] passing all the items of listbox in the richtextbox

查看:33
本文介绍了在富文本框中传递列表框的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将列表框的项目传递给富文本框?.我有多个项目,我希望它显示在 Richtextbox 中.这个项目就像收据.它显示项目及其数量.

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.

推荐答案

使用列表框执行此操作的问题之一是列表框将项目存储为对象并使用每个对象的 ToString 方法来显示该对象的表示.

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

这样,如果您使用不能隐式转换为字符串的对象,它仍然可以工作.或者,如果您使用自定义对象,则所需的只是类中的 ToString 覆盖.

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.

这篇关于在富文本框中传递列表框的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆