Combo Boxes for Data Lookup lazarus / 16-Databases ---------------------------------------------------------------------- SteveF · 2011-02-07 16:16 Can anyone point me to documentation/tutorials, or supply specific information on how to use either a TDBComboBox or TDBLookupComboBox to display a filtered list of items from a database, which can then be used to find one or more of those items from the database? When I use a  TDBLookupComboBox, it seems to insist that the ListSource, ListField, DataSource and DataField all be populated – this won’t do, since I need this combo to be “unbound” to any particular table.  If I leave the DataSource and DataField unpopulated, no items are displayed. I can get a  TDBComboBox connected to a DataSource, but when I do it only displays one item – useless for this situation. I can make a TDBGrid do what I want, but that takes up too much form real estate.  I really want to use a Combo Box for this task.  Help! Lazarus 0.9.28.2/FPC 2.2.4 ZEOS 6.6.6 Firebird 2.1 TIA, Steve ---------------------------------------------------------------------- ik · 2011-02-07 17:23 If I understand you correctly your approach is wrong. TDBLookupXXX is a "join" action between a foreign key and the table with the display of the information. TDBComboBox display the list of records of a specific datasource. Each selection on a list (TDBXXXCombo, TDBXXXList and TDBGrid) change the data pointer for the needed record. The filter you require can be used in a normal TComboBox and apply the filter itself to the query/filter property (I never worked with Zeos). ---------------------------------------------------------------------- xenblaise · 2011-02-07 19:32 I've tried this too, but I can't remember how did I arrived on the solution. Try TDBLookup, but I know you really want the tdBComboBox because it's a standard. ---------------------------------------------------------------------- SteveF · 2011-02-07 20:34 Quote from: ik on February 07, 2011, 06:23:37 pmIf I understand you correctly your approach is wrong. TDBLookupXXX is a "join" action between a foreign key and the table with the display of the information. TDBComboBox display the list of records of a specific datasource. Each selection on a list (TDBXXXCombo, TDBXXXList and TDBGrid) change the data pointer for the needed record. The filter you require can be used in a normal TComboBox and apply the filter itself to the query/filter property (I never worked with Zeos). OK, let’s get specific about what I’m looking for. BTW, my background is in VB and MS Access; I do this all the time in those environments.  This should be do-able in Lazarus, too. For example purposes, let’s use an order-tracking database.  I’m doing something different, but the programming flow and logic is identical. Two tables are involved: Companies and Orders.  Ideally I want two combo boxes.  The first one presents a sorted list of the companies in the Companies table.  SQL for this would be: SELECT DISTINCT CompID, CompanyName FROM Companies ORDER BY CompanyName; When the Company Name is selected from the first combo, I want to modify the SQL for the second combo so that it looks like this: SELECT OrderNo, OrderDate FROM Orders WHERE CompID = ORDER BY OrderNo; When the Order Number is selected from the second combo, then I want to jump directly to the matching order that’s already in the RowSet that populates the form. Steve ---------------------------------------------------------------------- xenblaise · 2011-02-08 02:51 I think you want a master-detail relationship  Try to see that; http://www.mediafire.com/file/wdb99x40alvjkxi/SQLdb_update2.zip ---------------------------------------------------------------------- SteveF · 2011-02-08 16:09 Quote from: xenablaise on February 08, 2011, 03:51:38 amI think you want a master-detail relationship  Try to see that; http://www.mediafire.com/file/wdb99x40alvjkxi/SQLdb_update2.zip Already have a master-detail relationship: between the order itself and the order detail items. Now I'm trying to build a search function to look up a specific order.  That's what the combo boxes are intended to do. Steve ---------------------------------------------------------------------- SteveF · 2011-02-09 16:22 No additional takers on this one? This should be a simple and elementary thing to do: 1. Populate some sort of combo box (I really don't care what type, but need to know which one to use) with the ResultSet of an SQL statement; 2. Determine which item in the ResultSet was selected, and take further action using a value from that selected item. As I mentioned in my original post, this is something I've easily been able to do in MS Access for over 10 years now.  Surely there's something similar here? In Access, I can populate a combo with two columns of SQL results, display only one of them (the human-readable one), and use the other (e.g. a Primary Key or Foreign Key value) as my determinant for the action to be taken in item 2 above.  This seems to be a real simple thing to do, but if it can be done with Lazarus it is definitely *not* IOTTMCO (Intuitively Obvious To The Most Casual Observer)! Steve ---------------------------------------------------------------------- xenblaise · 2011-02-10 11:54 http://forum.lazarus.freepascal.org/index.php/topic,8708.msg53999.html That is my final help, try to use that. ---------------------------------------------------------------------- xinyiman · 2011-02-10 12:29 Quote from: xenablaise on February 10, 2011, 12:54:22 pmhttp://forum.l azarus.freepascal.org/index.php/topic,8708.msg53999.html That is my final help, try to use that. ---------------------------------------------------------------------- SteveF · 2011-02-11 18:42 I downloaded and installed the TDBSimpleComponents, which now gives me some further questions to ask: How do I connect one of these components to my SQL data?  I see no property in the Object Inspector that allows me to do this.  There is also no documentation in the download file to tell me how to use these, which is what I need to be able to effectively use all the tools in the Lazarus component collection. I think I have an alternative method that will build the lookup capability in my application, but I haven’t tried it yet:  creating a temporary “dummy” ResultSet to which I can “bind” a  TDBLookupComboBox and at the same time grab the information I need to complete the lookup.  This seems really kludgey and inelegant to me, if someone has a better idea I want to hear about it! I need to mention that I generally like Lazarus, and I want to make it work for me!  I’m not a stupid person, but the Lazarus way of doing things is sufficiently different from my current development tools that I sometimes struggle to figure things out without guidance.  Unfortunately, guidance is something that is sometimes in short supply around here. ---------------------------------------------------------------------- xenblaise · 2011-02-12 16:03 I'll try to make you demo using tdbCombo with dataSource. Please wait ---------------------------------------------------------------------- xinyiman · 2011-02-14 07:03 Example: www.liuheschool.com/informatica/Lazarus/Esempi/Esempio_DBSimple.zip ---------------------------------------------------------------------- xinyiman · 2011-02-14 07:07 I am not able to put the functions I have written in the object inspector. If someone wants to do it for me would be very welcome. Thanks ---------------------------------------------------------------------- xenblaise · 2011-02-15 15:58 hi xinyiman; thank you for the samples, but does it really pick a data using your component? I hope ComboBox with datasource works on your component. Oh, hey, don't removed the link; or put it on a safe vault link, like mediafire ---------------------------------------------------------------------- SteveF · 2011-02-15 16:11 Thank you to both, I will look at the sample to see how it works. Steve ---------------------------------------------------------------------- xinyiman · 2011-02-15 16:25 Quote from: xenablaise on February 15, 2011, 04:58:03 pmhi xinyiman; thank you for the samples, but does it really pick a data using your component? I hope ComboBox with datasource works on your component. Oh, hey, don't removed the link; or put it on a safe vault link, like mediafire Do it all from the Code, should be the creation of form.