Combobox and Checkbox Default Edit Keys
Hi,
Is it possible to change the default keys that activate combobox and checkbox cells?
Instead of pressing F4 to activate a combox cell, I want to use the Enter Key.
Also, instead of pressing the Space bar to change the state of a checkbox cell, I want to use the Enter Key.
I have already changed the Enter key behaviour with:
GridControl1.EnterKeyBehavior = Syncfusion.Windows.Forms.Grid.GridDirectionType.None
If the default keys cannot be changed, what is the best way to achieve this?
Kind Regards
Mike
SIGN IN To post a reply.
3 Replies
AR
Arulpriya Ramalingam
Syncfusion Team
April 12, 2017 12:43 PM UTC
Hi Mike,
Thanks for your interest in Syncfusion products.
The default keys for the cell renderers cannot be changes via properties. But the default key behavior of F4 and space bar can be restricted by overriding the ProcessCmdKey method. The enter key behavior can be activated for ComboBox’s DropDown and checkBox’s CheckedValue can be using KeyDown event. Please make use of the below customization and sample,
Code snippet
Disabling default function of F4 and SpaceBar
| Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean If currentCell IsNot Nothing Then Dim rowIndex As Integer = currentCell.RowIndex Dim colIndex As Integer = currentCell.ColIndex Dim info As GridStyleInfo = Me.gridControl1.Model(rowIndex, colIndex) 'Restricting the F4 and SpaceBar function If (keyData = Keys.Space AndAlso info.CellType Is "CheckBox") OrElse (keyData = Keys.F4 AndAlso info.CellType Is "ComboBox") Then Return True End If End If Return MyBase.ProcessCmdKey(msg, keyData) End Function |
Activate Enter key function for CheckBox and ComboBox
| Private currentCell As GridCurrentCell 'Event Triggering AddHandler gridControl1.KeyDown, AddressOf gridControl1_KeyDown 'Event Customization Private Sub gridControl1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) If Me.gridControl1.EnterKeyBehavior = GridDirectionType.None Then currentCell = Me.gridControl1.CurrentCell Dim rowIndex As Integer = currentCell.RowIndex Dim colIndex As Integer = currentCell.ColIndex Dim info As GridStyleInfo = Me.gridControl1.Model(rowIndex, colIndex) 'Activate the enter key for checkbox If e.KeyCode = Keys.Enter AndAlso info.CellType Is "CheckBox" Then e.Handled = True If info.CellValue.ToString() = "true" Then info.CellValue = "false" Else info.CellValue = "true" End If End If 'Activate the enter key for combobox If e.KeyCode = Keys.Enter AndAlso info.CellType Is "ComboBox" Then e.Handled = True If Not currentCell.IsDroppedDown Then currentCell.ShowDropDown() Else currentCell.CloseDropDown(Syncfusion.Windows.Forms.PopupCloseType.Canceled) End If End If End If End Sub |
Regards,
Arulpriya
MN
mike newett
May 2, 2017 03:05 AM UTC
That worked great thanks.
I've expanded on your example to include the MonthCalendar & Textbox cell types (see end of post).
Whilst my solution works, I'm not sure it's the best way.
To finish editing, I'm calling:
currentCell.EndEdit()
currentCell.CancelEdit()
I'm having to call currentCell.CancelEdit() to remove the focus from the current cell.
For example, if the cursor is focused on the top line of a 5 line multi-line textbox when currentCell.EndEdit is called, the user would have to press the down arrow key 5 times before the focus moves to the next cell below. By calling CancelEdit after EndEdit, the user only has to press the down arrow key once to move the focus to the next cell below.
Is this the correct method, or show I be doing something else?
'Activate the enter key for calendar
If e.KeyCode = Keys.Enter AndAlso info.CellType Is "MonthCalendar" Then
e.Handled = True
If Not currentCell.IsDroppedDown Then
currentCell.ShowDropDown()
Else
currentCell.CloseDropDown(Syncfusion.Windows.Forms.PopupCloseType.Canceled)
currentCell.EndEdit()
currentCell.CancelEdit()
End If
Return
End If
If e.KeyCode = Keys.Enter AndAlso info.CellType Is "MonthCalendar" Then
e.Handled = True
If Not currentCell.IsDroppedDown Then
currentCell.ShowDropDown()
Else
currentCell.CloseDropDown(Syncfusion.Windows.Forms.PopupCloseType.Canceled)
currentCell.EndEdit()
currentCell.CancelEdit()
End If
Return
End If
'Activate the enter key for textbox
If e.KeyCode = Keys.Enter AndAlso info.CellType Is "TextBox" Then
e.Handled = True
If Not currentCell.IsEditing Then
currentCell.BeginEdit()
If e.KeyCode = Keys.Enter AndAlso info.CellType Is "TextBox" Then
e.Handled = True
If Not currentCell.IsEditing Then
currentCell.BeginEdit()
'Move cursor to end of text
Dim renderer = TryCast(currentCell.Renderer, GridTextBoxCellRenderer)
renderer.TextBox.SelectionStart = renderer.TextBox.TextLength
Dim renderer = TryCast(currentCell.Renderer, GridTextBoxCellRenderer)
renderer.TextBox.SelectionStart = renderer.TextBox.TextLength
Else
currentCell.EndEdit()
currentCell.CancelEdit()
End If
Return
End If
currentCell.EndEdit()
currentCell.CancelEdit()
End If
Return
End If
Kind Regards
Mike
AR
Arulpriya Ramalingam
Syncfusion Team
May 2, 2017 10:29 AM UTC
Hi Mike,
Thanks for your update.
We are glad to hear that the provided solution is resolved your scenario and we have analyzed your scenario for moving the current cell with multi-line textbox. The way you have tried to achieve the scenario was correct. The EndEdit() method will ends the editing mode and the CancelEdit() method will discards the changes in CurrentCell. Calling the CancelEdit() method after EndEdit() will save the changes and completes the editing mode. So, this will not cause any issues regarding your scenario.
Please let us know if you need any further assistance.
Regards,
Arulpriya
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
MN mike newett
- Apr 11, 2017 10:54 PM UTC
- May 2, 2017 10:29 AM UTC