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

Posted on 2005-03-11
Medium Priority
Last Modified: 2013-11-17
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,
Question by:barrydbrown
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 25

Accepted Solution

kode99 earned 2000 total points
ID: 13523317
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.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question