views:

1466

answers:

7

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

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

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

+3  A: 

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.

Gamecat
+3  A: 

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?

François
I want to create a filter for a table, and the listbox is one of the filter criteria. I want to fill the listbox with a table from the database.
Blue
A: 

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.

Jozz
+1  A: 

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.

Jeremy Mullin
A: 

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.

skamradt
+1  A: 

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.

+1  A: 

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.

Mason Wheeler