Typing Aid ComboBox

Overview

The current MFC combobox class is insufficient. The pop-down choicelists provided for the application I was writing needed to reduce the amount of typing a user must do. The user is given a list of items from which they can choose any combination of selections. When a selection is chosen from the list, it is placed into the field. This also helps to reduce the amount of spelling errors which can occur. Implementation Specfication This combo box will consist of an edit field with a pop down choicelist. The user can show the choicelist by left-clicking on the down-arrow button or by pressing alt- down or by pressing alt-up. The user can hide the choicelist by clicking in the field or by pressing alt-down or by pressing alt-up. By default, the choicelist is not shown when the field receives focus (eg, mouse click on the field).

When the user types, the field will automatically complete the typing if the substring typed matches the beginning of an item in the choicelist. The selection is completed by the user, if the user hits the right arrow key, or the end key, or types a space and that space is not contained within an item in the choicelist.

The field is subdivided into sections. Each section is delimited by a space. Each section can be autocompleted. There are 2 forms of autocompletion: when typing the first match in the choicelist appears in the field; or after typing some substring (or empty substring) the user can pop-down the choicelist to show only items which match that substring. The choicelist is reset, such that all choices will appear in the next section, when the completion finishes.

Any leading spaces will be removed from the completion match.

The key breakdown is:
right arrow, end key - finish autocompletion
spacebar - finish autocompletion only if space is not contained as part of a substring match
alt-down or alt-up or left-click button - show list of available choices
alt-down or alt-up or left-click in choicelist - hide choicelist, placing selection in field
left-click in field - hide choicelist if shown, cancelling selection

Enforced choicelists are supported. The behavior of an enforced choicelist changes so that the user can not type a value which is not an item in the choicelist. Also, the user can not delete single characters. If the user wishes to change a selection, the old selection must first be deleted, then the new selection can be made.

Design

A popup window with a list control as a child are attached to an edit control. A window with a pseudo-button is wrapped around the edit control to provide combobox-like functionality.

The edit control is modeled in similar style to MFC. However, I do not use Windows messages to provide functionality. Therefore, you can not assume that the following will work.

((CTypingAidEdit*)GetDlgItem(IDC_XXX))->GetTAESel() 
In the future, I will try to make this functionality available.

The edit control (as does the list control) derives from the respective MFC control as well as CSharedCtrlAttribs. This class is there to provide the ability to change the color of a control.

Please consult the .h files as an API reference.

Known Bugs

None

Example Usage

Here's an example of creating a dynamic combo box.
BOOL CTypingAidDemoDlg::OnInitDialog()
{
 // Usual Dialog Stuff here ...

 // Create the combo box
 m_pdynCombo = new CTypingAidCombo(TAES_HASLIST);
 m_pdynCombo->Create(CRect(100, 30, 200, 25), 
                     this, 
                     IDC_DYNCOMBO);

 // Set the colors
 CTypingAidEdit* pEdit = m_ppdynCombo[i]->GetEdit();
 pEdit->SetTextColor(RGB(255, 0, 0));
 pEdit->SetBkColor(RGB(0, 255, 255));

 // Add some columns and items
 CListCtrl* pListCtrl = m_ppdynCombo[i]->GetListCtrl();
 pListCtrl->InsertColumn(0, "From", LVCFMT_LEFT, 100);
 pListCtrl->InsertColumn(1, "Import Value", LVCFMT_LEFT, 100);
 LVITEM lvi;
 ::ZeroMemory(&lvi, sizeof(lvi));
 lvi.mask = LVIF_TEXT;
 lvi.iSubItem = 0;

 lvi.pszText = "Hello1";
 pListCtrl->InsertItem(&lvi);
 lvi.pszText = "Hello 2";
 pListCtrl->InsertItem(&lvi);

 pListCtrl->SetItemText(0, 1, "Apples");
 pListCtrl->SetItemText(1, 1, "oranges");

 // ...
}

Downloads

Download source - 24 Kb
Download demo project - 36 Kb


Comments

  • how to make the button disabled when the edit has no content!

    Posted by Legacy on 09/28/2003 12:00am

    Originally posted by: huaboy

    Thanks for the nice controll.I have used it in my application,but I want to make the button control disabled when no content typed in the edit field;only when the user starts to type something in the edit field,make the button visible!
    I can't find the button control in the source,please tell me the method how to change the button controll status!

    Reply
  • How to show the list control contents when the user start to type the text

    Posted by Legacy on 12/10/2002 12:00am

    Originally posted by: Ivaylo Geoirgiev

    Thanks for the nice controll.
    I want to use it in my application but it would be better if I can show all the items in the list controll when the user start to type something in edit field,like ShowDropDown(true) in the common combo box.
    My idea is that it to work like in MS Visio Studio.


    I've tried to show the list in CTypingAidEdit::OnChar(...)
    with Using ShowListBox(), but without success.

    Ivaylo Georgiev, BG

    Reply
  • unable to change font of CTypingAidCombo Object

    Posted by Legacy on 05/30/2002 12:00am

    Originally posted by: laxmikant p pa til

    when i created object of CTyingAid Combo , then i have successfully changed colour of control but i am not able to change font , because by default it takes , bold characters
    which is not looking good & takes too much space for small number of characters
    please send me answer as early as possible

    Reply
  • Undeclared symbol OBM_COMBO

    Posted by Legacy on 03/14/2002 12:00am

    Originally posted by: laxmikant panditrao patil

    Code gives error when used with other program
    it is giving error like undeclared symbol obm_combo
    what should i do for that

    Reply
  • Can you make autocomplete only working from the begining of the sequence?

    Posted by Legacy on 07/06/2001 12:00am

    Originally posted by: Ivaylo

    Hi
    Thanks for the nice control.

    I made it to work like custom control, with registerclass..
    It is more confortable to work with. If somebody is interested how I will show next.
    For my use I remove stack atribute and deleting all rows after making selection from user.
    In 'find match' function find some bug in exiting from while.

    But it is not a good idea autocomplete with substrins after user placing 'space bar'.

    Do you can correct it?

    By the way I very much like this style of explaining combobox.

    Ivaylo G.
    Swisscom Ltd.


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds