cardoso Posted November 5, 2019 Posted November 5, 2019 How can i set KeyValue to load text of an item on UniDBLookupComboBox when it is with the property "RemoteQuery" set to "True"? When i use a Data Source linked to the "ListSource" this works perfectly. But when i try to do using RemoteQuery, the UniDBLookupComboBox field doesn't display the selected item. I tried to run manually the event to force item load: UniDBLookupComboBoxEmployeeRemoteQuery('My item value', UniDBLookupComboBoxEmployee.Items); UniDBLookupComboBoxEmployee.KeyValue := 'My item value'; But it doesn't work, the field keeps empty. How to reproduce: Add a button to "DBLookupComboBox - Custom Remote Query" example and in the "OnClick" event try to select an item like: UniDBLookupComboBox1.KeyValue := 1651; // or [].Text := '1651'; Quote
arilotta Posted June 4, 2020 Posted June 4, 2020 Me too I'm having the same problem. Please someone provide us with a solution. Thanks Quote
Sherzod Posted June 4, 2020 Posted June 4, 2020 55 minutes ago, arilotta said: Me too I'm having the same problem. Please someone provide us with a solution. Hello, OnGetKeyValue ? \FMSoft\Framework\uniGUI\Demos\Desktop\DBLookupComboBox - Custom Remote Query (CDS) Quote
x11 Posted June 4, 2020 Posted June 4, 2020 try my code procedure TUnimForm1.comboNovoComplexGetKeyValue(const Value: string; var KeyValue: Variant); begin comboOnGetKeyValue(qFill, Value, KeyValue); end; procedure TUnimForm1.comboNovoComplexRemoteQuery(const QueryString: string; Result: TStrings); begin comboOnRemoteQuery(qFill, 'TABLE_NOVOCOMPLEX', QueryString, Result); end; .... procedure comboOnGetKeyValue(q: TUniQuery; const Value: string; var KeyValue: Variant); begin if q.Active then KeyValue := q.Lookup('name', Value, 'ID'); end; procedure comboOnRemoteQuery(q: TUniQuery; const sTable, QueryString: string; var Result: TStrings); Var n: integer; begin q.Close; q.SQL.Text := 'SELECT ID, NAME FROM ' + sTable + ' WHERE UPPER(NAME) CONTAINING(UPPER(:NAME)) AND DELETED IS DISTINCT FROM 1'; if (QueryString.Length <= 2) and (QueryString <> '*') then exit; if (QueryString = '*') or (QueryString = '[null]') then q.Params[0].AsString := '' else q.Params[0].AsString := QueryString; q.Open; if q.RecordCount = 0 then begin Result.Add(constEmptyRes); exit; end; n := 0; q.First; while not q.Eof do begin Result.Add(q.FieldByName('name').AsString); q.Next; inc(n); if N > 100 then Break; end; end; Quote
arilotta Posted June 5, 2020 Posted June 5, 2020 Thanks Sherzoed and x11. I've already implemented the dblookup with remote query, and it works fine. What I'm non able to achieve is to initialize the combo with a value, for example when the form is created. Sherzod, given the demo: \FMSoft\Framework\uniGUI\Demos\Desktop\DBLookupComboBox - Custom Remote Query (CDS) Is it possible to open the form and have UniDBLookupComboBox1 already initialized with an given item without have the user to open the combo and sarch for it ? Please have a look at the screen shot for an example. Keep in mind that I've set ForceSelection to TRUE. Quote
x11 Posted June 5, 2020 Posted June 5, 2020 I'm not sure if I understood you correctly? but ... UniDBLookupComboBox1.Text := 'bla-bla-bla'; UniDBLookupComboBox1.keyvalue := 1073; Quote
arilotta Posted June 5, 2020 Posted June 5, 2020 Thanks x11. Your solution does not work, because if you set ForceSelection to TRUE, the component does not allow you to set the Text directly (the Text you specify is not present in the item list, that is empty as long as you manually enter some text in the combo and the event OnRemoteQuery is called and you populate the Result TStrings) You should populate the item list in advance in some manner, I think that some EXTJS trick is necessary,. Quote
arilotta Posted June 10, 2020 Posted June 10, 2020 Sherzod you're my last chance... Think about it, it is not just a trivial problem. Given the demo you mentioned: \FMSoft\Framework\uniGUI\Demos\Desktop\DBLookupComboBox - Custom Remote Query (CDS) in which you can search 300K records (employees) with a TDBLookupComboBox using remote query. Let's say that this combo is placed in a dialog used to input orders; in this dialog you can enter the Order ID, Saled Date, Ship Date and the Customer (similar to the demo). When a new order is created, the dialog opens with all fields empty, and the user should select ther Order ID, the dates and the customer. But when an order is edited, I expect the fields populated with the current order values: Order ID, Sales Date, Ship Date and also the Customer. And here is where the problem arises: how to initialize the combo with the current customer for the order ? Hope there is a solution, because tdblookupcombos with remote search are very powerful as long as there is the possibility to initialize the current value by code. Hope also to have clearly explained the problem I'm facing Thanks Andrea Quote
Sherzod Posted June 10, 2020 Posted June 10, 2020 Hi Andrea, Maybe somehow in the beginning you need to use a filter, enable only this "record" and disable RemoteQuery? Quote
cardoso Posted June 10, 2020 Author Posted June 10, 2020 Maybe giving an answer with another question isn't so useful? With RemoteQuery set to True, it doesn't work. Its simple. Quote
AmericoKutomi Posted October 13, 2020 Posted October 13, 2020 Hi, I had the same problem and found a solution. In my case, DBLookupComboBox has a datasource and datafield. Consider DBLookupComboBox.datafield is MyField. When the statement MyField.AsInteger:= 1 is called programatically, the correspondent item in the DBLookupComboBox is not selected. The solution is to add the statement: DBLookupComboBox.UpdateText; Apparently, UpdateText does manually the work that should be automatic by a data aware component as TDBLookupComboBox. I hope this can help others. Quote
x11 Posted October 14, 2020 Posted October 14, 2020 @Sherzod how about support key value by unimDBLookupComboBox/uniDBLookupComboBox item with RemoteQuery? and my question is still not resolved http://forums.unigui.com/index.php?/topic/14857-программно-заполнить-unimdblookupcombobox-и-выбрать-значение/ Quote
Stemon63 Posted October 15, 2020 Posted October 15, 2020 The true problem is that if I don't modify anything in the lookup, the previous field value (record value) must be showed always, also if there is ForceSelection to true. All operation (force selection, etc...) must be started ONLY if I edit the field, because, on record show, the store is empty and naturally editor value is deleted. So ForceSelection, Yes, but only when I manually modify the editor content. Always on lookups: Another my request feature is multi column display in the popup. Now we have to use Xtemplate and works extracting substrings for manage more column, but we don't have a key column to return comfortable exact record. Simply "Id" and "val" generate in the store is very poor for lookup management. We are looking (and working) for alternative solutions with stores at client level. Any improvement are appreciated. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.