Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 29 Mar 2024, 14:37

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Lookup in Grid
PostPosted: 04 Dec 2018, 12:27 
Offline

Joined: 16 Aug 2017, 14:24
Posts: 6
Is it possible to lookup both by key and value in dbgrideh? For example i have a table:

ID VALUE
1 MALE
2 FEMALE

When in dbgrid column i enter M, i get a combobox of possible values from dictionary. I want to be able, for example enter 1 and get MALE as value. Is it possible?


Top
 Profile  
 
 Post subject: Re: Lookup in Grid
PostPosted: 06 Dec 2018, 13:45 
Offline

Joined: 08 May 2014, 18:06
Posts: 660
Hello

There are no special properties for that but you can use TColumn.NotInList event to assign
RefId field when user enter 1 or 2 in the EditBox.

Code:
procedure TForm1.DBGridEh1Columns1NotInList(Sender: TObject; NewText: string;
  var RecheckInList: Boolean);
begin
  if DicMemTable.Locate('Id', NewText, []) then
  begin
    //Assign RefId field in the MainDataSet
    MemTableEh1RefDicId.Value := DicMemTable.FieldByName('Id').Value;
    RecheckInList := False;
  end;
end;


You also need to set Column.LimitTextToListValues = False to allow enter any vlaues in the LookupComboBox

Demo Project is attached


Attachments:
2018-12-06-LookupWithEnterKeyValueEnabled.zip [2.08 KiB]
Downloaded 125 times

_________________
Best regards
EhLib Support Team
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group