Set KeyValue of a TAdvDBLookupComboBox programmatically

Hi! I have a problem to set KeyValue of a TAdvDBLookupComboBox via programm code. I want to set the KeyValue to a specific value to set a default value. How is there right way to do that?

The code I tried is like following ...

        if LookupComboControl.ListSource.DataSet.RecordCount > 1 then
        begin
          LookupComboControl.ListSource.DataSet.locate('INT_RefCode', 1, []);
          LookupComboControl.OnCloseUp(LookupComboControl);
        end;

If the ListSource has more than one entry I want to set the entry with INT_RefCode = 1 as default. But the text of that entry is not showing up. It is like a null value in the text.

Can you help me please? How can i set the KeyValue to the a specific entry in ListSource?

Thanks!

I see you perform this action on the ListSource. Based on your description, I would think you need this on DataSource?

Yes, you're right. We need this on DataSource. Should I better set the KeyField of the DataSource to the located value?

LookupComboControl.Datasource.DataSet.FieldByName(KeyField).AsString := LookupComboBox.ListSource.DataSet.FieldByName('TXT_Kurztext').AsString;

My understanding of your request is that should give you the expected result.

Thank you for your help Bruno! I will try it next time. You can close this topic.