using maskedit control to allow entry and then scrolling a dblookupcombobox to closest match

For simply nefarious reasons, I want to have two MaskEdit controls on a lookup form. The first lookup box is to allow finding a patient by patient number. As you type in the patient number, a dblookupcombo box at the bottom of the screen opens and the matching name and patient number is shown.

The second maskedit control allows the user to search by name. Again, as you type in the name, the dblookupcombo box opens and scrolls to the nearest match.

My problem is that I cannot determine what to do to cause the dblookupcombo box to show the current record as selected. The record always appears in the middle of the scroll box, but is not highlighted. Is there any way to force the record to be selected. I have tried setting the KeyValue to the current patient number, but still no highlight.

Any light on the subject would be appreciated.

Thanks in advance,
Who is Participating?
kode99Connect With a Mentor Commented:
The reason that you are not able to get the selection text to highlight is probably that the KeyValue is not a exact match.  If it does not match it cannot be 'selected'.  By doing a seperate lookup with FindNearest() on a name table I could get the selection to highlight but even this was not reliable.  Sometimes it would not find the right one or would not highlight at all.

This in the OnChange of the Edit control,
  DBLookupComboBox1->KeyValue =  Table1->FieldByName("Name")->AsString;

I think you would need to make a new component based on the TDBLookupComboBox to get the behaviour you want.  

Here is an alternative method that I have used for customer lookup forms,  it can has a similar behaviour to what I think you are looking for.

Put two edits down - one for the number and another beside it for a name.  Now drop a TDBGrid below and make two columns - number and name and link it to the Table.  You can make this grid hidden.   Set the RowSelect and AlwaysShowSelection to true.

Now in the numbe edit put a OnChange like this,
  Table1->IndexName = "<numberindex>";
  Table1->FindNearest(ARRAYOFCONST((NumberEdit->Text)));  // where Table1 is indexed on the number.
  Table1->Visible = true;  // make the grid appear (if you have it hidden)

Same thing for the Name edit but put the index to the name index.

So now when the user starts typing anything in either box it will pop open the grid that will automatically show the closest match found to the typed entry.    When a final selection is made hide the grid.

You can then spruce it up for better appearance and customize the operation to suit you needs.

Anyway hope this is helpful.
All Courses

From novice to tech pro — start learning today.