Hello Support,
We are currently working on providing excel like functionality in a xamDataGrid, i.e, navigating within the grid using the arrow keys, the tab key and the enter key. This was possible by setting the property CellClickAction="SelectCell".
However, we also require a cell's value to be edited without double clicking the cell or pressing the F2 key; and navigating to another cell using the navigation keys. We did find a work around for this by use of the following code.
Private Sub xamGrid_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.KeyEventArgs)
Try
Dim currentCell As Cell = DirectCast(sender, XamDataGrid).ActiveCell
If (e.Key = Key.Enter Or e.Key = Key.Return) Then
CType(sender, XamDataGrid).ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges)
CType(sender, XamDataGrid).ExecuteCommand(DataPresenterCommands.CellBelow)
End If
If (currentCell Is Nothing OrElse currentCell.Field.Settings.AllowEdit = False) Then
Exit Sub
keyPressed = e.Key
If (previousFieldName <> currentCell.Field.Name Or previousRowNo <> currentCell.Record.Index Or keyPressed = Key.Escape) Then
previousFieldName = currentCell.Field.Name
previousRowNo = currentCell.Record.Index
firstKeyStroke = True
decimalValue = ""
If (currentCell.IsInEditMode = False And keyPressed = Key.Space) Then
If (firstKeyStroke = True) Then
firstKeyStroke = False
currentCell.Value = " "
Else
currentCell.Value = currentCell.Value & " "
ElseIf (currentCell.IsInEditMode = False And keyPressed = Key.Delete) Then
currentCell.Value = ""
ElseIf (currentCell.IsInEditMode = True) Then
If (keyPressed = Key.Up Or keyPressed = Key.Down) Then
e.Handled = True
Catch ex As Exception
End Try
End Sub
Private Sub xamGrid_PreviewTextInput(ByVal sender As System.Object, ByVal e As System.Windows.Input.TextCompositionEventArgs)
If (currentCell.IsInEditMode = False And (keyPressed <> Key.Enter Or keyPressed <> Key.Return)) Then
If (keyPressed = Key.Back) Then
ElseIf (currentCell.Field.DataType.FullName = "System.Decimal") Then
If ((keyPressed = Key.Decimal Or keyPressed = Key.OemPeriod) And Not decimalValue.Contains(".")) Then
decimalValue = ".0"
currentCell.Value = Convert.ToDecimal(decimalValue)
decimalValue = "."
ElseIf (IsNumeric(e.Text)) Then
decimalValue = e.Text
currentCell.Value = e.Text
If (currentCell.Value.ToString().Length <> 0) Then
currentCell.Value = currentCell.Value.ToString().Substring(0, currentCell.Value.ToString().Length - 1)
If ((keyPressed <> Key.Decimal And keyPressed <> Key.OemPeriod) And IsNumeric(e.Text) And _
decimalValue.Length < 10) Then
decimalValue = decimalValue & e.Text
decimalValue = decimalValue & ".0"
decimalValue = decimalValue.TrimEnd("0")
ElseIf (decimalValue <> "") Then
currentCell.Value = currentCell.Value & e.Text
By using the above code, editing the existing records was possible, i.e. the RecordUpdating event was fired. But when trying to enter into a add new record (i.e. the AllowAddNew="True"), the RecordUpdating event does not fire, and hence the record never gets added.
We also noticed that CellUpdating and CellUpdated events are called on every text input using the above code, which is not required as these events contain validation; and every text input makes the validation fail, as this should happen only before and after the cell is updated and not during text input.
We have also attached a video for your reference.
Waiting for your reply.
Thank You.
Thanks Stefan,
That works for me.
Hello Ramlagan,
In NetAdvantage 16.1 we introduced the IsAutoEditModeEnabled Property of the FieldSettings, which, when set to true, allows the user to enter cell’s editing mode by start typing when a cell is active. Here you can find more information about this:
https://ko.infragistics.com/help/wpf/xamdatapresenter-conf-editing
Hi,
This question was raised quite a long time back 6 years!
Is this feature released?
Hi [dhorth],
As a starting point, I had sent the attached VB.NET sample to the original customer in a private support case in November, but we never heard back from them, and the case was closed due to inactivity. The sample modified the PreviewKeyDown event slightly, in the hope of resolving just the issue with firing the CellUpdating/CellUpdated with each keystroke.
I have since moved to another department and have not yet worked time for forums back into my schedule, so I think the best option for you to get a full resolution to this issue would be to log a privavte support case, and in the case, you can reference this thread. The URL for the Support Request Submit page is:
http://ko.infragistics.com/support/submitrequest.aspx
Thanks,
[EDIT] - I am not able to attach the sample to my reply somehow...if you log a support case, you can mention the original private case number CAS-76285-SBN4V9...which has the starting-point sample attached to it. The Developer Support Eningeer should be able to retrieve that sample for you.
Does the lack of a response, mean there is not resolution?!