Link to home
Start Free TrialLog in
Avatar of Crius
Crius

asked on

CTreeCtrl typedown doesn't accept spaces

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.
Ex:
Document ID
Document State
Document Version
etc...
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...

Summary:
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.
Avatar of DanRollins
DanRollins
Flag of United States of America image

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
Avatar of Crius
Crius

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Crius

ASKER

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. :)
Avatar of Crius

ASKER

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.
>>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

Avatar of Crius

ASKER

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. :)