Solved

CTreeCtrl typedown doesn't accept spaces

Posted on 2002-05-31
7
535 Views
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.
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.
0
Comment
Question by:Crius
  • 4
  • 3
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
0
 
LVL 3

Author Comment

by:Crius
Comment Utility
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.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
Comment Utility
Another thought,
You could attack it from a different direction: Make the strings shorter and remove spase.  Rather than
   Document Version
use
   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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Author Comment

by:Crius
Comment Utility
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. :)
0
 
LVL 3

Author Comment

by:Crius
Comment Utility
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.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
>>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

0
 
LVL 3

Author Comment

by:Crius
Comment Utility
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. :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now