Download demo project - 19
Kb
Download source - 4 Kb

This article describes a class (CACEditCtrl) for an
Auto-Completion Edit Control, which can be used small data sets, such as
most-recently-used account numbers, etc.
It works by iterating over a collection of STL strings
and tries to find a matching beginning-substring in the entry. It is
not the most the most effecient way of doing it, but it works well for small
data sets.
The two functions of interest are:
void AddACEntry( LPCTSTR cpEntry )
void DisableAC( bool bDisable = true )
The AddACEntry(...) function is used
to add a string to the control's collection of strings. No duplicate
checking is done. Why? Because this control acts as a container for
data, not a manager of data.
The DisableAC(...) function allows you to
turn the Auto-Completion feature on or off.
In the demo image above, the numbered dialogs show the
operation of the control as 3 characters are typed into it :"T", "h", and
"a" as shown below:
- No characters typed
- A "T" was typed into the control, and it auto-completed
with its first match
- A "h" was typed into the control, ditto above
- An "a" was typed into the control, and there were no
matches to auto-complete for
Conditions of use are detailed in the header and
source file(s).
Feel free to contact me if there are any questions. Have
fun.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 13 of 13 (Total in Forum: 13) (Refresh) | FirstPrevNext |
|
 |
|
 |
there is a bug when use with muliline style Moveing the code into function OnChar will solve this problem. but Is there any other method to solve it without moveing the code?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Absolutely!
Peace!
-=- James Please rate this message - let me know if I helped or not!
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I think it might be confusing to users that the first matching entry is "auto-completed" when there are more than one matching entries. (I guess this depends on the app somewhat.) In the example, typing T should not complete to "TDFX" since "This is a test" also starts with T.
In this case, you probably need a drop-down list that shows all the matching entries for the user to select from - like the way the File Open dialog works in W2K, and edit controls in IE5 if you have "auto-complete" turned on.
Has someone written something like this?
Andrew Phillips andrew @ expertcomsoft.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
Nice job, but users should also consider the auto-complete combo box the Chris Maunder did. I am not sure why you would use the edit control version instead of the combo box version
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
> Nice job, but users should also consider the auto-complete combo box the Chris Maunder did.
By searching the site, they can find it.
> I am not sure why you would use the edit control version instead of the combo box version.
It simply provides a different interface. Why use a listview control over a List Box if you are only dealing with single column items? It depends on the requirements of the interface.
In a form-based interface, you may not be familiar with a combo-box that is marked "username" or "account". An edit control looks more natural.
If you do not have a use for the Edit Control based one, you are free to use the Combo-Box based one.
-=- James
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
> Your example fails to show whther or not the match is case-sensitive..
Yer right. That is what the link for the source code is for! 
The compare is a case sensitive compare. Changing the _tcsncmp(...) function to a _tcsnicmp(...) function is an easy fix, if you need case insensitive comparisons.
-=- James
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
General
News
Question
Answer
Joke
Rant
Admin