Jump to content

Programmatically set DBLookupComboBox item with RemoteQuery


cardoso

Recommended Posts

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';

 

Link to comment
Share on other sites

  • 6 months later...
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)

 

Link to comment
Share on other sites

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;

 

 

Link to comment
Share on other sites

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.

screenshot.png

Link to comment
Share on other sites

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,.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 months later...

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.

Link to comment
Share on other sites

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.

     

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...