从数据库列中选择Tlistbox项 [英] Tlistbox items from database column

查看:198
本文介绍了从数据库列中选择Tlistbox项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用数据库列中的项目填充 TListbox 控件?

Is there a way to populate a TListbox control with items from a database column?

我知道这样做的正确方法是简单地使用 DBLookupListbox 控制,并将其设置为访问列我想,但问题是,当我单击查找控件中的项目之一,它更改数据集中的当前行(预期行为),但我不希望这种情况发生。

I know the proper way to do this is to simply use a DBLookupListbox control and set it up to access the column I want, but the problem with that is when I click on one of the items in the lookup control, it changes the current row in the dataset (expected behavior) but I do not want this to happen.

相反,我希望当前行仅在查找控件中的双击事件时更改,由于我不认为此行为可能更改,我认为简单地使用正常的 TListBox 会更容易,但正如我上面所说,我不知道如何做。

Instead, I would want the current row to be changed only on a double click event in the lookup control and since I do not think this behavior is possible to change, I thought it would be easier to simply use a normal TListBox instead, but as I stated above, I am not sure how it's done.

因此,我再次向专家们介绍了如何填充正常的 Tlistbox 控件

So once again, I have come to the experts for some advise on how to populate a normal Tlistbox control with items from a database column.

推荐答案

有很多方法可以解决您的问题。你可以创建一个破解的TDbLookupListBox控件,并重写Click方法不做任何事情。您还可以创建要用于查找的第二个数据集。但是,如果你愿意,填充一个TListbox,你只需重复数据集,并添加字段值到列表框为:

There are a myriad of ways to solve your problem. You could create a hacked control of a TDbLookupListBox and override the Click method to do nothing. You could also create a second dataset to be used for your lookup. But as you wish, to populate a TListbox, you simply iterate the dataset and add the field value to the listbox as:

tLogin.first;
while not tLogin.eof do
begin
  Listbox1.Items.Add(tLogin.fieldbyname('fullname').asstring);
  tLogin.next;
end;

如果您需要基于选择的键值,那么这不会完全解决您的问题。你最好是黑客TDbLookupListbox控件,imo。

If you need a key value based on a selection, then this won't solve your problem entirely. You'd be better off hacking the TDbLookupListbox control, imo.

这篇关于从数据库列中选择Tlistbox项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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