event KeyDown (KeyCode as Integer, Shift as Integer)
Occurs when the user presses a key while an object has the focus.

 TypeDescription 
   KeyCode as Integer An integer that represent the key code.  
   Shift as Integer An integer that corresponds to the state of the SHIFT, CTRL, and ALT keys at the time of the event. The shift argument is a bit field with the least-significant bits corresponding to the SHIFT key (bit 0), the CTRL key (bit 1), and the ALT key (bit 2). These bits correspond to the values 1, 2, and 4, respectively. Some, all, or none of the bits can be set, indicating that some, all, or none of the keys are pressed. For example, if both CTRL and ALT are pressed, the value of shift is 6.  
Use KeyDown and KeyUp event procedures if you need to respond to both the pressing and releasing of a key. You test for a condition by first assigning each result to a temporary integer variable and then comparing shift to a bit mask. Use the And operator with the shift argument to test whether the condition is greater than 0, indicating that the modifier was pressed, as in this example:

ShiftDown = (Shift And 1) > 0
CtrlDown = (Shift And 2) > 0
AltDown = (Shift And 4) > 0
In a procedure, you can test for any combination of conditions, as in this example:
If AltDown And CtrlDown Then

Use the Editor property to assign an editor to a node. Use the Mask property to mask input characters while user types inside the node's editor. Use the Numeric property to specify whether the editor enables numeric values only. Use the Editing property to check whether the control is running in edit mode.

The following VB sample starts editing a node as soon as user presses the F2 key:

Private Sub XMLGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    With XMLGrid1
        If .Editing = 0 Then
            If KeyCode = vbKeyF2 Then
                .Edit
            End If
        End If
    End With
End Sub
The following C++ sample starts editing a node as soon as user presses the F2 key:
void OnKeyDownXmlgrid1(short FAR* KeyCode, short Shift) 
{
	COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
	if ( m_xmlgrid.GetEditing() == 0 )
		if ( *KeyCode == VK_F2 )
			m_xmlgrid.Edit( vtMissing );
}

The following VB.NET sample starts editing a node as soon as user presses the F2 key:

Private Sub AxXMLGrid1_KeyDownEvent(ByVal sender As Object, ByVal e As AxEXMLGRIDLib._IXMLGridEvents_KeyDownEvent) Handles AxXMLGrid1.KeyDownEvent
    If (AxXMLGrid1.Editing = 0) Then
        If (e.keyCode = Keys.F2) Then
            AxXMLGrid1.Edit()
        End If
    End If
End Sub

The following C# sample starts editing a node as soon as user presses the F2 key:

private void axXMLGrid1_KeyDownEvent(object sender, AxEXMLGRIDLib._IXMLGridEvents_KeyDownEvent e)
{
	if (axXMLGrid1.Editing == 0)
		if (e.keyCode == Convert.ToUInt16(Keys.F2))
			axXMLGrid1.Edit();
}

The following VFP sample starts editing a node as soon as user presses the F2 key:

*** ActiveX Control Event ***
LPARAMETERS keycode, shift

with thisform.XMLGrid1
	if ( .Editing = 0 ) 
		if ( keycode = 113 )
			.Edit
		endif
	endif
endwith

 


Send comments on this topic.
© 1999-2011 Exontrol.COM, Software. All rights reserved.