如何允许在 TDBLookupComboBox 中选择 NULL 值? [英] How to allow selecting a NULL value in a TDBLookupComboBox?
问题描述
我有一个 TDBLookupComboBox
显示一个 TStringField
类型的 fkLookup
,它允许 Null
值(来自可为空的整数数据库列).
I have a TDBLookupComboBox
showing a TStringField
of kind fkLookup
, which allows Null
values (from a nullable Integer database column).
下拉列表显示分配的 LookupDataSet
中的项目,该项目来自连接表.如果字段为Null
,则不显示任何列表项,组合框为空.如果该字段有值,则会显示正确的描述.
The dropdown list displays the items from the assigned LookupDataSet
, which comes from a joined table. If the field is Null
, none of the list items are displayed, the combobox is empty. If the field has a value, the correct description is shown.
我可以通过按分配的 NullValueKey
将其重置为 Null
.
I can reset it to Null
by pressing the assigned NullValueKey
.
没关系,但用户更喜欢使用鼠标.所以我可以提供一个清晰的按钮,但我认为列表顶部的附加行会好得多.我该怎么做?
That's all ok, but the users prefer using the mouse. So I could provide a clear button, but I think an additional row on top of the list would be much better. How can I do that?
推荐答案
您可以将空行放入查询中,如果需要对其进行排序,可以将其显示在列表顶部,如下所示:
You can put the empty row in your query, and if you need it sorted you can make it appear at the top in your list like this:
select 0 as sort,
convert(int, null) as UserID,
'Clear' as Name
union all
select 1 as sort,
u.UserID,
u.Name
from tblUser u
order by sort, Name
sort
列将使其显示在顶部,之后您可以根据需要进行排序.
The sort
column will make it appear at the top, after that you can sort on whatever you need.
这篇关于如何允许在 TDBLookupComboBox 中选择 NULL 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!