Go Premium for a chance to win a PS4. Enter to Win


CTreeCtrl typedown doesn't accept spaces

Posted on 2002-05-31
Medium Priority
Last Modified: 2013-11-20
When you start typing in a CTreeCtrl, the item selection moves to highlight the item matching what you have thus far typed. After about 2 seconds, the buffer of what you have typed is reset. This also happens in CListCtrls, Windows directories, the common control dialog for file->open, etc.

The problem:
I have populated a tree control with many items. Each item has several words, but all items are unique.
Document ID
Document State
Document Version
When I start typing "Document" it selects the first document (Document ID) properly, but when I hit the spacebar, the control beeps at me, and doesn't allow me to simply type "V" to select "Document Version".

I have read in a few articles on Codeguru that spacebar has been used to check and uncheck items, though I'm not sure if this is its true purpose or not.

The question:
How can I add the space to the typedown buffer so I can simple type "Document V" to select the Document Version in my CTreeCtrl derived class.

The Exceptions:
I already have easy access to code from codeguru.com and codeproject.com that show how I might create, from scratch, searching functions all myself. I suppose I could generate a 2 second delay watch, and maintain my own buffers to hold the typedown text, but I post here in the hopes that someone has a better solution.

This code will be used in a development team environment, so the less code there is (and the more we use MFC stuff), the earier it will be to maintain. So, I will not accept the simple answer of just recoding the whole typedown, especially since I can already do this myself...

More or less, to be able to append a space to the internal buffer kept by MFC when using Typedown on a CTreeCtrl.

I have set the initial points at 200, but if this is not enough, I will raise it.
Question by:Crius
  • 4
  • 3
LVL 49

Expert Comment

ID: 7048539
I've looked around and there seems to be no 'magic bullet' solution to this request.  The 'Incremental Search' logic is embedded inside of the TV Common Control and the documentation says that it appends only 'character keys' to the search string.  That would appear to rule-out the SPACE character.

I thought I'd found a clever workaround by typing Ctrl+Space (with the idea of converting space to ^Spc  programmatically) but it seems to work only for one additional character (I may be misinterpretting what it is doing.... perhaps you can figure it out).  

I also found a quick way to make SPACE work like a down-arrow -- your user could type the first word, then lean on the space bar to move down the list.

There may be some oddball undocumented window style bit or perhaps a way to locate the address of the incremental search string buffer and hack around that way, but that would be bad idea.

You question is well-defined and clearly-worded, but I wonder why you resist the obvious solution:  

* Write a CTreeCtrl-derived object that intercepts SPACE.
* Use TVM_GETISEARCHSTRING to get the search string to that point
* Append a space and retain the string.
* Continue collecting character codes, and do your own search to move the highlight.

You are looking for a 'less code is better' solution --- which I fully understand -- but once you have written a clean CTreeCtrl-derived object, you can use it anywhere that you use CTreeCtrl -- you move it into your utilities folder and never look at it again.

Finally I wonder about your basic premise:  Do you really think somebody will type...

    Document Version

into a Tree Pane?  In general, the incremental search is designed to let you type the first few characters and get into the ballpark, then you arrow down to zero-in.  When the need is more complex, a separate search facility is normally provided.

Note that the Tree pane in the Windows Explorer has the same limitation.  There is no similar problem with the ListView, so perhaps if it is really important, you can switch to using the ListView when you have such a long list of lengthy space-riddled strings.

-- Dan

Author Comment

ID: 7049673
Thank you for looking into this! I'm not at work now, but will look at this ctrl-space thing.

I resist the obvious solution because I'm a cheapskate. :) I know the obvious solution, and don't really want to pay 200 question points just to have someone tell me to use the obvious solution. I wanted a better solution than the obvious one because I felt there must be some way to access that buffer that I just couldn't find.

If no better solution is provided by this question, of course I will go with the obvious one, but I would like to consider the question unanswered in that case.

As for the basic premise, yes. People are typing in the words and it is well known that the users prefer to be "keyboard only" because going to the mouse takes up time. This is actually a customer request that surprised me, but it must be done.
LVL 49

Accepted Solution

DanRollins earned 800 total points
ID: 7050023
Another thought,
You could attack it from a different direction: Make the strings shorter and remove spase.  Rather than
   Document Version
   DocVersion - Document Version

Now the user can easily keyboard D O C V and if you have info tips turned on, the entire text is available for viewing (rest the mouse over it).

>>How can I add the space to the typedown buffer so I can
>> but I would like to consider the question unanswered in that case.

Actually, when a negative "It can't be done" is a full and correct answer -- no matter how dissapointing -- it deserves the points.  It often takes longer for a concientious, knowlegable Expert to be able to say "no can do" than it does to find a positive answer.  Think about it: I spent over two hours on research and trying several back-door techniques before I posted.

However, in the case of a "no," you are more justified in leaving the question open for a while longer just in case somebody can come up with a "yes" solution.  

-- Dan
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 7051161
I suppose you are right. I was going to give you 50 points for your hard work, but I guess "no can do" really is a good answer. It's the same answer I came up with though (and I spent 2 hours at least researching too). Thank you for your research and time. It's always good to get a second opinion. :)

Author Comment

ID: 7051311
You mentioned the following:

The 'Incremental
Search' logic is embedded inside of the TV Common Control and the documentation says that it appends
only 'character keys' to the search string.  That would appear to rule-out the SPACE character.

Where is this documentation? I was unable to locate it in the MSDN.
LVL 49

Expert Comment

ID: 7051809
>>Where is this documentation?  
The TVN_KEYDOWN notif gives the hint.  It was one of the things I tried... It is possible to exclude a key from the search by handling this notif, but I coudln't see any wahy that that could help with this particular problem.

The term 'embedded' is my own phrasing implied by the fact that if you do no processing on space, the control handles it itself.  If you tell it to ignore space, then the search string does not get longer.  So it is hardwired into the control (hardwired is my own term, also).

-- Dan


Author Comment

ID: 7051927
Ah, I had missed that sentence.

I've implemented the search by the way. Took an hour and 100 lines of code, so not as bad as I had first thought. Works great. It still feels like dancing around the issue, but I think it'll be fine, as long as no one tries to change it. :)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

916 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