Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ctrl + <other key> only picks up Ctrl

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
erikest



Joined: 30 May 2007
Posts: 17

PostPosted: Thu Aug 02, 2007 7:30 pm    Post subject: Ctrl + <other key> only picks up Ctrl Reply with quote

I'm trying to implement the standard Ctrl+c, Ctrl+v (copy/paste) functionality on my tree rows. I'm handling the key_down event (and the key_press I've tried as well), but it only ever picks up the first key. So Ctrl+c in the key_down handler only sees Ctrl, and the c never comes through, not even as a separate event. Any ideas?

Thanks,
_________________
Erik Taylor
Developer
EnergySoft, LLC.
Back to top
View user's profile Send private message
erikest



Joined: 30 May 2007
Posts: 17

PostPosted: Thu Aug 02, 2007 9:11 pm    Post subject: Reply with quote

Am I retarded? I'm trying something even simpler... I just want to expand the row when the user presses the right arrow key. The funny thing is, the event handler's (key_press or key_down) never get called when I press the right arrow (left arrow). Is the tree suppressing key strokes? Can I turn that 'feature' off? It also suppresses the down (up) arrow unless I'm at the last (first) visible row.

Thanks,
_________________
Erik Taylor
Developer
EnergySoft, LLC.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Aug 02, 2007 11:11 pm    Post subject: Reply with quote

Quote:
I just want to expand the row when the user presses the right arrow key.


This is the default behaviour - check out the samples.

Quote:
I'm trying to implement the standard Ctrl+c, Ctrl+v (copy/paste) functionality on my tree rows. I'm handling the key_down event (and the key_press I've tried as well), but it only ever picks up the first key.


You should be able to do this handling the key down event eg

Code:
        private void testTree_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control)
            {
                switch (e.KeyCode)
                {
                    case Keys.V:
                        Debug.WriteLine("Here");
                        break;
                }
            }
        }


An alternative is to override the ProcessCmdKey method. Make sure you call the base method or you will lose all keyboard navigation in the tree.

You can also override one of the two methods that this calls:

ProcessNormalCmdKey - for handling key events when there is no editor currently active
ProcessEditCmdKey - for handling key events when there is an active editor
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
erikest



Joined: 30 May 2007
Posts: 17

PostPosted: Fri Aug 03, 2007 12:28 am    Post subject: Reply with quote

Hmm.. What could cause this default behavior to fail. It really seems like something is catching my key presses and suppressing them. I've tried everything on the simple example I sent in for the IDataErrorInfo problem and Ctrl+<whatever> works and so does the default behavior for the arrow keys. In my more complex tree, only up and down arrows work. Could anything with objectrowbindings be causing key press suppression? Could ProcessCmdKey be erroring out and killing the event handlers?

Could the default behavior have been modified or changed through a property or something?

This is really baffling.

I appreciate the code for the Ctrl+v, it looks just like the code I have in there already. The problem is that it never registers the v. Something captures the ctrl, supresses the v and passes the ctrl to the keyDown. The v disappears into the ether.

Like I was saying before, nothing happens at all when I press the right or left arrow keys, it doesn't even fire an event handler. So even if the default behavior was working, I wouldn't be able to do anything else with these key presses - they don't register. This is the case in the IDataErrorInfo sample I sent you guys earlier too. If you handle the key down event, you'll see that pressing the right arrow key doesn't trigger a key down event. In fact, the behavior seems inconsistent here, now that I look at it. Here's what I'm seeing in the sample, tell me if the same happens on your end:

1) Debug the project
2) select "Parental Unit" aka the first row
3) press right arrow key
4) notice that the values of the bound text boxes change, indicating that selected item has changed
5) notice that the tree did not expand and the currently selected row is not visible
6) press right again and the tree expands and the correct row is selected
7) press left and the selected row becomes the first row
Cool press left again and the rows collapse
9) press right and the row expands but the selection does not move
10) press right a final time and the selection moves.
11) if you have a break point inside a keydown handler, you'll notice that pressing right didn't fire the event anywhere

Any help on what's going on would be great.
_________________
Erik Taylor
Developer
EnergySoft, LLC.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Aug 03, 2007 12:42 am    Post subject: Reply with quote

Quote:
1) Debug the project
2) select "Parental Unit" aka the first row
3) press right arrow key
4) notice that the values of the bound text boxes change, indicating that selected item has changed
5) notice that the tree did not expand and the currently selected row is not visible


This is probably happening because you still haven't fixed the sample code to notify virtual tree after you created the child rows. Since you aren't using binding lists you need to notify VirtualTree of changes you make to the datasource (by calling UpdateRows). If you don't then you can expect some strange behaviour.

Otherwise the behaviour looks normal to me. It is the same behaviour you get with standard windows explorer tree. The right/left key events are handled by the VirtualTree.ProcessCmdKey method - that's why you don't get them in the KeyDown event. If you wanted to changed the behaviour of these you'd have to override one of the ProcessCmdKey methods.

I'm not sure what is catching your Control-V in your application but one possibility is that if you define Control-V as a shortcut in a menu for the form then the menu will catch this key event and virtual tree won't get the event.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
sbass



Joined: 16 Aug 2007
Posts: 4

PostPosted: Fri Dec 14, 2007 5:21 pm    Post subject: Reply with quote

I ran into this in other contexts earlier. If you define the shortcut keys for Cut/Copy/Paste in the menu, these are not available to the control. So standard TextBox or other controls which know how to handle Ctrl-C, never get the chance.

After seraching around on the web, what works for standard controls is to send a Windows message to the control. The code looks sort of like this

private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
SendMessage(GetLowestActiveControl(ActiveControl).Handle, WM_CUT, IntPtr.Zero, IntPtr.Zero);
}

where the GetLowestActiveControl walks down through containers to find the active control. The standard controls have Cut/Copy/Paste methods that can handle the Windows message.

I need the same behavior in the VT. But it does not have base class methods that respond to these messages that I can override to implement the behavior I need.

Is there any way to get at this behavior?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Dec 14, 2007 9:40 pm    Post subject: Reply with quote

If you want Virtual Tree to handle the WM_CUT window message then you would need to override the WndProc method eg

Code:
        protected override void WndProc(ref Message m)
        {
            const int WM_CUT = 0x0300;
 
            if (m.Msg == WM_CUT)
            {
                // do whatever
            }
            else
            {
                base.WndProc(ref m);
            }
        }

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group