如何允许在TDBLookupComboBox中选择NULL值

如何允许在TDBLookupComboBox中选择NULL值

本文介绍了如何允许在TDBLookupComboBox中选择NULL值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TDBLookupComboBox 显示了 fkLookup TStringField c>,它允许 Null 值(来自可为空的Integer数据库列)。

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.

我可以通过按来将其重置为 Null 分配 NullValueKey

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

排序列将使其显示在顶部,之后您可以根据需要进行排序。

The sort column will make it appear at the top, after that you can sort on whatever you need.

这篇关于如何允许在TDBLookupComboBox中选择NULL值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 10:44