Click here to Skip to main content
Licence Public Domain
First Posted 9 Mar 2004
Views 60,438
Bookmarked 39 times

Rapid data entry: An edit box with a history

By | 20 Jun 2004 | Article
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

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questioncan that be done for combo box ? PinmemberShay Harel10:31 20 Oct '06  
AnswerRe: can that be done for combo box ? PinmemberJohan Rosengren19:55 20 Oct '06  
GeneralRe: can that be done for combo box ? PinmemberShay Harel3:15 23 Oct '06  
GeneralRe: can that be done for combo box ? PinmemberJohan Rosengren9:01 23 Oct '06  
GeneralProblems with MSVC.NET compile Pinmemberamw157455:48 4 Mar '06  
GeneralRe: Problems with MSVC.NET compile PinmemberJohan Rosengren9:32 5 Mar '06  
If the demo app compiles, and yours do not, you'll have to compare the projects to see the difference. First of all, check the includes in stdafx.h, and see that they match. You might also want to compare any #define's. I don't develop under NET, so I can't give you more help than this. You might try to initialize the CString by using a ctor parameter instead of an assignment, in pseudocode, change CString xxx = yyy to CString xxx(yyy), on the offending line.

QuestionHow to use in CFormView PinmemberClevedon_Peanut15:09 13 Jun '04  
AnswerRe: How to use in CFormView PinmemberJohan Rosengren19:43 13 Jun '04  
Generalnice PinmembermailMonty18:46 22 Mar '04  
GeneralAmazing - 5++ PinmemberA sleepy one6:41 10 Mar '04  
GeneralRe: Amazing - 5++ PinmemberJohan Rosengren8:11 10 Mar '04  
GeneralRe: Amazing - 5++ PinmemberA sleepy one21:45 10 Mar '04  
GeneralRe: Amazing - 5++ PinmemberJohan Rosengren22:18 10 Mar '04  
GeneralRe: Amazing - 5++ PinmemberJohan Rosengren0:24 17 Mar '04  

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.

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