I have a XamGrid with a requirement to be able to move between cells with either a tab key or enter key. The reason is that it is highly data entry intensive and the folks doing the data entry want to minimize usage of mouse and tab keys. If they could, they would like to stay within the number pad area of the keyboard.
Consequently, I have to aid the navigation from cell to cell, and even skip over appropriate cells. Therefore, I am processing the CellExitedEditMode event, and based on the cell exiting, I am throwing you into edit mode into the next logical cell. Without this logic, the enter key would never advance the editing function.
There is a bad side effect however. When you click on a button to commit changes, the grid is still in edit mode. And based on the logic of how I have to navigate you around, you will basically never leave edit mode on this grid. So the button event never fires. That is unless in the CellExitedEditMode event, I can find out the source of the event and see if it is a button and then exit the edit mode of the grid.
For reference, I have included the code I am using in this event, to give you a flavor of what is going on. Unfortunately, this code is being hit on button press, and it is in effect cancelling the button click event. Any advice would be appreciated.
The bottom line is that I would like to be able to know in the cellexiteditmode event that I am exiting as a result of a button click. I guess alternatively, I could try and do a "client event" on the button to kick the grid out of edit mode? Don't know if this is possible in Silverlight.
Private Sub dgDataEntry_CellExitedEditMode(sender As Object, e As Infragistics.Controls.Grids.CellExitedEditingEventArgs) Handles dgDataEntry.CellExitedEditMode Dim dgRow As Row = Nothing Dim c As Cell = Nothing If Not e.Cell Is Nothing Then Me._intDataEntryIndex = e.Cell.Row.Index Select Case e.Cell.Column.Key.ToLower() Case "projid" If Not e.Cell.Value Is Nothing AndAlso e.Cell.Value <> String.Empty Then Me._proxyCR.SFProjectNameAsync(CType(e.Cell.Value, String), New SFCallResult()) End If c = Me.dgDataEntry.Rows(Me._intDataEntryIndex).Cells(2) If Me.dgDataEntry.EnterEditMode(c) = False Then MessageBox.Show("Could not place cell in edit mode") End If Me.dgDataEntry.EnterEditMode() Case "orgabbrvcd" If Not e.Cell.Value Is Nothing AndAlso e.Cell.Value <> String.Empty Then Me._proxyCR.SFValidOrgAsync(CType(e.Cell.Value, String), New SFCallResult()) End If c = Me.dgDataEntry.Rows(Me._intDataEntryIndex).Cells(3) If Me.dgDataEntry.EnterEditMode(c) = False Then MessageBox.Show("Could not place cell in edit mode") End If Me.dgDataEntry.EnterEditMode() Case "glacctid" Dim f As SFDetailItem = CType(e.Cell.Row.Data, SFDetailItem) If Not f.GLAcctId Is Nothing AndAlso f.GLAcctId <> String.Empty Then Me._proxyCR.SFValidAcctAsync(f.ProjId, f.GLAcctId, New SFCallResult()) End If c = Me.dgDataEntry.Rows(Me._intDataEntryIndex).Cells(4) If Me.dgDataEntry.EnterEditMode(c) = False Then MessageBox.Show("Could not place cell in edit mode") End If Me.dgDataEntry.EnterEditMode() Case "qty" c = Me.dgDataEntry.Rows(Me._intDataEntryIndex).Cells(5) If Me.dgDataEntry.EnterEditMode(c) = False Then MessageBox.Show("Could not place cell in edit mode") End If Me.dgDataEntry.EnterEditMode() Case "price" c = Me.dgDataEntry.Rows(Me._intDataEntryIndex).Cells(7) If Me.dgDataEntry.EnterEditMode(c) = False Then MessageBox.Show("Could not place cell in edit mode") End If Me.dgDataEntry.EnterEditMode() End Select End If End Sub
Hello,
I am just checking if you require any further assistance on the matter.
Sincerely,
Ekaterina
Developer Support Engineer
Infragistics
www.infragistics.com/support
Thanks for this recommendation. I like your approach better than the workaround I devised last night. I had decided to set a boolean to short circuit my logic based on the Mouse Enter event of the button. IE, if you hover over the button, I threw you out of edit mode of the grid.
I took your suggestion and switched the boolean logic to the positive for the CellControl...
If Not focusedElement Is Nothing AndAlso TypeOf focusedElement Is Infragistics.Controls.Grids.CellControl Then
I think one possible way to handle this scenario is to check whether the button is the currently focused element when exiting edit mode, and if yes - to not execute the code in ExitedEditMode event.
Here's an example in C#:
private void igGrid_CellExitedEditMode(object sender, CellExitedEditingEventArgs e) { object focusedElement = FocusManager.GetFocusedElement(); if (focusedElement != null && focusedElement is Button) { return; } // Your custom logic here // ... }
Hope this helps,