Blue
Blue

Reputation: 403

Multiselect listbox bound to database in Delphi 6

I'm using Delphi 6, and I want a database bound list box with multiselect. I found three types of List boxes: TListBox, TDBListBox and TDBLookupListBox.

As far as I can understand, TListbox is not bound to database. TDBListBox and TDBLookupListBox can't be multiselected.

Is there a way to get a multiselect listbox binded to database?

Upvotes: 4

Views: 3965

Answers (7)

Toon Krijthe
Toon Krijthe

Reputation: 53456

The problem with databinding components is that they rely on a datasource and a datasource has only a single cursor. That is probably the reason why.

By the way, do you need to change the data? Else you could fill a normal listbox from a dataset. Or even use an invisible data listbox and copy the contents to a normal listbox.

Upvotes: 4

Mason Wheeler
Mason Wheeler

Reputation: 84650

If you fiddle with some of the options of a TDBGrid and restrict the columns it displays, you can make something that looks a whole lot like a listbox. Try setting the Options property to [dgTitles,dgTabs,dgRowSelect,dgAlwaysShowSelection,dgCancelOnExit,dgMultiSelect] and work from there.

Upvotes: 1

user30586
user30586

Reputation: 27

You could create your own custom listbox component that descends from TCustomListBox and add a Datasource property for your list, and another property such as TStrings to be used as a container to hold selected values. You could then post changes to your database using a button click.

Upvotes: 1

Jeremy Mullin
Jeremy Mullin

Reputation: 4250

DevExpress TcxDBListBox supports multiselect. I use their multiselect drop down check box bound to a database, it's sweet.

The components have methods you can implement to convert to and from your list; EditValueToStates and StatesToEditValue. While the data I store is not normalized (I store a semi-colon delimited list of version numbers), I created a full text search index on the field, with a semi-colon as a delimiter, and now I can still perform optimized searches on that field.

Upvotes: 1

skamradt
skamradt

Reputation: 15548

Based on your comment to François, I would use a normal TListbox and write code to insert all distinct values into the list, and then handle the multi-select values yourself. Jeremy's solution also works, and the DevExpress Express Quantum Grid has a nice filter system which might even save you some other programming.

Upvotes: 0

Jozz
Jozz

Reputation: 608

In a TDbLookupListBox you have the option to bind two different things to data; first you can bind the list to a dataset (ListSource/ListField/KeyField), second you can bind the selected item to a field in another dataset (DataSource, DataField). There is nothing conceptually wrong with wanting to bind the list of items to a dataset, and then manually manage multiple selections, however I don't think it is possible with the current implementation without subclassing and enabling the required control styles.

Upvotes: 0

Francesca
Francesca

Reputation: 21650

Not as far as I know.
The standard is that you offer with the list a bunch of values in which 1 represents the current record.
Unless you have a multivalued field (against best practices) I can't see how you could multiselect...

Or what you might want is actually a sub-table?

Upvotes: 3

Related Questions