TDBAdvSearchEdit

Hello,

I struggle to use the TDBAdvSearchEdit component:

  1. If I add to the component 3 columns for example, what is the code to retrieve the data in column2 of the selected line ?

  2. Is it possible to bind the datasource and datafield to a certain column ? or it’s always the first column by default .

Regards

  1. The value in other columns can be retrieved with:

dbadvsearchedit.Items[itemindex].Captions[columnindex]

  1. The datafield per column can be set with:

dbadvsearchedit.Columns[columnindex].DataField

Hi,

Concerning 1):

Does it mean that for each '“columnindex” ,we need to define an “item.itemindex” ?

I’m not sure I understand.
ItemIndex is the index of the row in the dropdown list. The active row or selected row is indicated by DBAdvSearchEdit.ItemIndex

Hi

I have one DBAdvSearchEdit component connected to a customer listsource.

This listsource has two fields (customer_name and customer_id)
In the DBAdvSearchEdit, I have created two TColumnItems for each field:
TColumnItems[0] for the customer_name and TColumnItems[1] for the customer_id

When the user choose a customer in the list, I want to retrieve the customer_id from TColumnItems[1] ?

(DBAdvSearchEdit.Datasource and DBAdvSearchEdit.Datafield are empty for this case.)

Regards

From the OnSelect event, you could have an event handler like:

procedure TForm1.DBAdvSearchEdit1Select(Sender: TObject);
var
id: string;
begin
id := DBAdvSearchEdit1.Items[DBAdvSearchEdit1.ItemIndex].Captions[CustomerIDColumn];
end;

Hello,

It’s works fine, this is exactly what I wanted to do.

Now, to go further, is it possible to link to another table "order_table" which has the cliend_id identifier ?

With the same settings as before, I add on the DBAdvSearchEdit component :
datasource:=order_source
datafield:=client_id

But it doesn't work because the client_id is in column 1 ?
Is there any possibility to match the table ?

Regards

Did you consider a TQuery as a listsource where you JOIN the two tables in the query?

Hi,

I wrote something wrong in my explanation of my morning post !

Here is the good text:

Is it possible to link to another table "order_table" which has the “customer_id” identifier ?

With the same settings as before, I add on the DBAdvSearchEdit component :
datasource:=order_source;
datafield:=DBAdvSearchEdit1.DataField := TDBColumnItem(DBAdvSearchEdit1.Columns[1]).DataField ;

Now, when I navigate in the "order_table" , i can see the customer_id changing.
But I see the identifier “customer_id”, not the customer_name in the component ?

Maybe , something I don’t understand ?
I want the same behaviour of the TAdvDBLookupComboBox.

There is at this moment not a similar link via a KeyField in TDBAdvSearchEdit like there is in TAdvDBLookupComboBox
The DBAdvSearchEdit.ListSource is used to fill the search list and the DataSource is used to link the text value in the DBAdvSearchEdit to a dataset