如何将空值或自定义值添加到绑定的组合框? [英] How to add empty or custom value to a bound combobox?

查看:63
本文介绍了如何将空值或自定义值添加到绑定的组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用绑定到Category表的System.Windows.Forms.Combobox
作为搜索条件。当用户不想使用此条件时,我需要选择一个 All值或空字符串。由于组合是绑定的,因此每次单击组合时,都会删除combo1.Text = All添加的值。显然,我无法将所有类别添加到数据库中。做到这一点的最佳方法是什么?

I am using a System.Windows.Forms.Combobox bound to Category table as search criteria. I need to have a value "All" or empty string that will be selected when user does not want to use this criteria. Since combo is bound, each time it is clicked, value added by combo1.Text = "All" is erased. Obviously, I can’t add "All" category to database. What is the best way to accomplish this?

推荐答案

在其他值都被取值之后,手动将全部条目添加到绑定数据集中加载或取消绑定组合,而是遍历数据以填充它。这只是一个搜索组合,因此您实际上并不需要绑定的所有好处。

Either manually add the All entry to the bound dataset after the other values have been loaded, or unbind the combo and instead iterate through the data to populate it. It's just a search combo, so you don't really need all the benefits of binding.

这篇关于如何将空值或自定义值添加到绑定的组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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