如何在组合框中不显示空对象 [英] How to don't display null object in combobox
问题描述
大家好,
我的框架:visual studio 2008 + sql server 2005
我有自己的数据库。它有col1栏:
row1:faefe1
row2:faefe1
row3:null
row4: faefe2
row5:faefe2
row6:null
row7:null
row8:faefe1
row9:faefe1
我的窗口表单应用程序包括1个组合框控件,它被限制在上面的数据库中:
hello everyone,
my framework: visual studio 2008 + sql server 2005
I had my own database. it have "col1" column:
row1:faefe1
row2:faefe1
row3:null
row4:faefe2
row5:faefe2
row6:null
row7:null
row8:faefe1
row9:faefe1
my window form application include 1 combobox control, it is bounded to above database:
DataView dv_filename = new DataView();
dv_filename.Table = table;
comboBox1.DataSource = dv_filename;
comboBox1.DisplayMember = "col1";
上面的组合框显示声明。
如何显示它(意味着删除空对象):
row1: faefe1
row2:faefe1
row3:faefe2
row4:faefe2
row5:faefe1
row6:faefe1
请帮帮我。非常感谢!
combobox dislay as above declare.
how to display it as (mean that remove null object):
row1:faefe1
row2:faefe1
row3:faefe2
row4:faefe2
row5:faefe1
row6:faefe1
please help me. thank you very much!
推荐答案
表
,我猜你是通过执行一些查询得到的。因此,您需要更新该查询以包含Where条件,例如......
Thetable
, I guess you got by executing some query. So, you need to update that query to include a Where condition something like...
SELECT col1
FROM
TableName
WHERE
Col1 <> ''
在你的查询,将null或空转换为空白并在下拉列表中显示值。
In your query, convert null or empty into an empty space and display values in the dropdown.
您可以尝试通过过滤绑定组合框的表中的空值。请尝试如下:
you can try by filtering the null values from the table you are binding your combo box with. Try as below:
DataView dv_filename = new DataView();
var table1 = from t in table
where t.col1 != NULL
select t;
dv_filename.Table = table1;
comboBox1.DataSource = dv_filename;
comboBox1.DisplayMember = "col1";
或者您可以在数据库中执行相同操作类似这样的事情:
or you can do the same in DB from where you are getting the table something like this:
select colms from table where col1 IS NOT Null;
这篇关于如何在组合框中不显示空对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!