Type | Description | |||
Long | A long expression that indicates the window's handle for the built-in editor that's focused while the control is running in the edit mode. |
Use the Editing property to check whether the control is in edit mode. Use the Editing property to get the window's handle for the built-in editor while editing. Use the Edit method to start editing the focused cell. Use the EditType property to define the column's editor. Use the ReadOnly property to make the control read only. Call the EditClose method to close the current editor. The EditingText property returns the caption being shown on the editor while the control runs in edit mode. The Editing property returns a not-zero value only if called during the EditOpen, Change or EditClose event.
The edit events are fired in the following order:
Edit event. Prevents editing cells, before showing the cell's editor.
EditOpen event. The edit operation started, the cell's editor is shown. The Editing property gives the window's handle of the built-in editor being started.
Change event. The Change event is fired only if the user types ENTER key, or the user selects a new value from a predefined data list.
EditClose event. The cell's editor is hidden and closed.
The following VB sample closes the current editor if the user presses the enter key:
Private Sub Grid1_KeyDown(KeyCode As Integer, Shift As Integer) With Grid1 If Not (.Editing = 0) Then If (KeyCode = vbKeyReturn) Then .EditClose KeyCode = 0 End If End If End With End Sub
The following C++ sample closes the editor when user hits the enter key:
void OnKeyDownGrid1(short FAR* KeyCode, short Shift) { if ( *KeyCode == VK_RETURN ) if ( m_grid.GetEditing() != 0 ) { m_grid.EditClose(); *KeyCode = 0; } }
The following C# sample closes the editor when user hits the enter key:
private void axGrid1_KeyDownEvent(object sender, AxEXGRIDLib._IGridEvents_KeyDownEvent e) { if (Convert.ToUInt32(e.keyCode) == Convert.ToUInt32(Keys.Enter)) if (axGrid1.Editing != 0) { axGrid1.EditClose(); e.keyCode = 0; } }
The following VB.NET sample closes the editor when user hits the enter key:
Private Sub AxGrid1_KeyDownEvent(ByVal sender As Object, ByVal e As AxEXGRIDLib._IGridEvents_KeyDownEvent) Handles AxGrid1.KeyDownEvent If (Convert.ToUInt32(e.keyCode) = Convert.ToUInt32(Keys.Enter)) Then With AxGrid1 If Not (.Editing = 0) Then .EditClose() e.keyCode = 0 End If End With End If End Sub
The following VFP sample closes the editor when user hits the enter key:
*** ActiveX Control Event *** LPARAMETERS keycode, shift if ( keycode = 13 ) &&vkReturn with thisform.Grid1.Object if ( .Editing() != 0 ) .EditClose() keycode = 0 endif endwith endif
If your application still requires the string that user types into an text box inside the exGrid control. you can use the following VB trick:
Private Sub Grid1_Change(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long, NewValue As Variant) ' Finds the text inside the text box, in case that NewValue parameter is changed to a valid data Debug.Print getWndText(getEditWnd(Grid1)) End Sub Private Function getEditWnd(ByVal g As EXGRIDLibCtl.Grid) As Long Dim h As Long h = GetWindow(g.hwnd, GW_CHILD) While Not (h = 0) If (getWndClass(h) = "HolderBuiltIn") Then getEditWnd = GetWindow(h, GW_CHILD) Exit Function End If h = GetWindow(h, GW_HWNDNEXT) Wend getEditWnd = 0 End Function Private Function getWndText(ByVal h As Long) As String Dim s As String s = Space(1024) GetWindowText h, s, 1024 getWndText = To0(s) End Function Private Function getWndClass(ByVal h As Long) As String Dim s As String s = Space(1024) GetClassName h, s, 1024 getWndClass = To0(s) End Function Private Function To0(ByVal s As String) As String To0 = Left$(s, InStr(s, Chr$(0)) - 1) End Function
The sample requires the following API declarations:
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Private Const GW_CHILD = 5 Private Const GW_HWNDNEXT = 2
The following C++ sample displays a message box with the caption that user types inside the text box of an editor:
HWND getEditWnd( HWND h ) { TCHAR szName[1024] = _T(""); h = GetWindow( h, GW_CHILD ); while ( !( h == 0 ) ) { GetClassName( h, szName, 1024 ); if ( _tcscmp( _T("HolderBuiltIn"), szName ) == 0 ) return GetWindow( h, GW_CHILD ); h = GetWindow( h, GW_HWNDNEXT ); } return 0; } void OnChangeGrid1(long Item, long ColIndex, VARIANT FAR* NewValue) { HWND h = getEditWnd( m_grid.m_hWnd ); if ( h ) { TCHAR szText[1024] = _T(""); ::GetWindowText( h, szText, 1024 ); ::MessageBox( NULL, szText,NULL, NULL ); } }