Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.


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

Technology Partners: 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!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

730 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