Click here to Skip to main content
Click here to Skip to main content

Rapid data entry: An edit box with a history

, 20 Jun 2004
Rate this:
Please Sign up or sign in to vote.
A way of simplifying rapid data entry

Sample Image - bufferededit.gif

Introduction

For rapid data entry, the normal solution with a drop down list where earlier entries can be selected is not always of any help. A drop down is far too interactive, and demands - in my opinion - quite a lot of concentration on the part of the user.

This class is far simpler - close to annoyingly basic. It stores the entries from the edit box in a CStringArray, and this list can be navigated by pressing the page up or page down keys. As an added feature, pressing the right-arrow key when the cursor is located at the right end of the text will - if appropriate - add the character at this same position in the last history string to the edit box. Ctrl+PgUp will find the previous item of the history in alphabetical order, Ctrl++PgDn the previous. If the appropriate style is set, the history will be circular (wrap around) and/or sorted (non-case sensitive). It might also be autocompleting, and the max size of the history can be set.

Using the code

CBufferedEdit is a simple CEdit-derived class. It can be instantiated dynamically, by calling Create, or from a dialog template.

The class has a private CStringArray member m_history, which holds the earlier strings. The current contents of the edit box is added to this array as soon as WM_SETTEXT is sent to the control (such as when SetWindowText is called), The class also contains a private int member - m_current - holding the current position in the list.

WM_CHAR is mapped, of course, for handling VK_PRIOR, VK_NEXT and VK_RIGHT.

As the history strings are set, a few contortions has to be made in the code to remove them from the history list - otherwise, SetWindowText would have triggered the WM_SETTEXT-mapping, and strings would have been added to the history by just navigating it. This is accomplished in UpdateFromHistory.

Public interface

void CBufferedEdit::ClearBuffer()

Clears the history buffer and resets the current pointer

void CBufferedEdit::SetBufferStyle( int style )

Sets the buffer style for the control. Styles can be ORed together. The styles are:

BES_CIRCULAR - when the current pointer reaches either the start or end of the history, the pointer is moved to the other end of the history array.

BES_AUTOCOMPLETE - The control tries to complete the current input from the history after each keypress.

BES_SORT - The history is sorted at all times. No duplicates are added.

The history will be cleared, so this function should normally be called during startup.

void CBufferedEdit::SetBufferMax( int max )

Sets the maximum number of history strings. Set to 0 if no max is to be used. The history will be cleared, so this function should normally be called during startup.

int CBufferedEdit::GetBufferStyle()

Returns the current style of the control

int CBufferedEdit::GetBufferMax()

Returns the current max number of history entries.

Points of Interest

This was not a difficult class to write, as far as the implementation goes. Tricky was to get it to work intuitively, however. Should the text be selected when a new history string is displayed? Should the right arrow show the last history string, or the current? As it works now, it is perfectly adapted for my intended use, but it goes to show that it is perhaps not the programming itself that is a problem, but rather creating something that works in a productive manner.

History

  • 2004/06/15 - As per a suggestion from Clevedon_Peanut (thanks for the feedback!), I've added automatic handling of the ENTER-key by adding a new style, BES_AUTOFILL. If this style is set, the ENTER-key empties the edit field and adds the string to the buffer. This avoids having a default key for the updates, and thus works better for several edits on the same dialog, or in a form view.
  • 2004/04/22 - The ico and rc2 added to the res-directory, and as per a suggestion, I added a release-build exe.
  • 2004/04/16 - Added history entry max, circular buffer, sorted buffer, sorted navigation and autocompletion.
  • 2004/04/10 - Initial version.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

About the Author

Johan Rosengren
Software Developer (Senior) Abstrakt Mekanik AB
Sweden Sweden
45 years old, married, three kids.
 
Started with computers more than 20 years ago on a CBM-64.
 
Read Theoretical Philosophy at the University of Lund.
 
Working as a C++ consultant developer.
 
Science-fiction freak. Enjoy vintage punkrock.

Comments and Discussions

 
Questioncan that be done for combo box ? PinmemberShay Harel20-Oct-06 10:31 
AnswerRe: can that be done for combo box ? PinmemberJohan Rosengren20-Oct-06 19:55 
GeneralRe: can that be done for combo box ? PinmemberShay Harel23-Oct-06 3:15 
GeneralRe: can that be done for combo box ? PinmemberJohan Rosengren23-Oct-06 9:01 
GeneralProblems with MSVC.NET compile Pinmemberamw157454-Mar-06 5:48 
GeneralRe: Problems with MSVC.NET compile PinmemberJohan Rosengren5-Mar-06 9:32 
QuestionHow to use in CFormView PinmemberClevedon_Peanut13-Jun-04 15:09 
AnswerRe: How to use in CFormView PinmemberJohan Rosengren13-Jun-04 19:43 
Generalnice PinmembermailMonty22-Mar-04 18:46 
GeneralAmazing - 5++ PinmemberA sleepy one10-Mar-04 6:41 
GeneralRe: Amazing - 5++ PinmemberJohan Rosengren10-Mar-04 8:11 
GeneralRe: Amazing - 5++ PinmemberA sleepy one10-Mar-04 21:45 
GeneralRe: Amazing - 5++ PinmemberJohan Rosengren10-Mar-04 22:18 
GeneralRe: Amazing - 5++ PinmemberJohan Rosengren17-Mar-04 0:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 21 Jun 2004
Article Copyright 2004 by Johan Rosengren
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid