如何更新列表框中的显示值? [英] How do I update shown value in listbox??

查看:120
本文介绍了如何更新列表框中的显示值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家们(我希望)...

我遇到了一个大问题:
我创建了一个列表框,并在Item-collection中添加了自己的类.
该类具有一个称为标题"的属性,该属性作为DisplayMember传递到列表框.
当用户选择其他项目时,代码将从表单中获取信息并将更改存储到对象中,该对象是之前选择的,然后使用新选择的对象中的数据填充表单.

到目前为止一切都很好.

我的问题是-简而言之-我找不到一种方法来告诉列表框更新显示的值,用户可能已更改了该值,并且我使用它来显示底层对象中的其他字段已更改,方法是在值后附加*.

我已经尝试了列表框上公开的所有方法,甚至尝试实现INotifyPropertyChanged接口,但是这些方法都没有运气.

有人可以告诉我该怎么做(或者怎么做)!

对于包含大量信息(有关其他任何信息的网站)的问候和感谢.

克劳斯H
丹麦

Hi experts (I hope)...

I''ve run into a big problem:
I''ve created a listbox, and added my own class in the Item-collection.
The class has a property called "Caption", which are delivered to the listbox as DisplayMember.
When the user selects a different item, the code grabs information from the form and store changes into the object, that was selected before, and afterwards fills the form with data from the newly selected object.

So far so good.

My problems is - in short - that i can''t find a method to tell the listbox to update the shown values, the user might have changed the value and i use it to show that other fields are changed in the underlyiong objkect, by appending an * to the value.

I''ve tried all methods exposed on the listbox and even tried to implement the INotifyPropertyChanged interface, but no luck with any of these.

Can someone PLEASE tell me what to do (or rather HOW to do it)!

Regards and Thanx for a site with lots of information (about anything else...)

Claus H
Denmark

推荐答案

为ListBox绑定一个BindingSource,而不是将对象直接添加到ListBox中,并使用BindingSource的ResetCurrentItem方法更新列表.

您还可以在类中重写ToString方法,以控制文本在ListBox中的显示方式.
Bind the ListBox a BindingSource instead of adding your objects directly to the ListBox and use the ResetCurrentItem method of the BindingSource to update the list.

You can also override the ToString method in your class to control the way text is shown in the ListBox.


这篇关于如何更新列表框中的显示值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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