Hello.
Does anyone know how to force cells of XamDataGrid to always be in edit mode? Clicking a cell automatically places it in edit mode, but simply navigating the grid with arrow keys or tab keys, requires the press of F2 to place the cell in edit mode.
My current project needs more of an Excel-type functionality where the user can quickly navigate and type with as few keystrokes as possible.
Thanks in advance,
Steve Wall
Hello,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
After playing with your solution a little bit more I noticed that you can no longer use the arrow keys to move the cursor around in the text when editing a cell, since we changed the arrow keys to move the user to the next cell. While it does solve the initial problem mentioned in this thread, I didn't like it.
So I modified your solution to the following instead. Basically it just causes a cell to enter edit mode whenever Enter or the Spacebar is pressed, as I think these are more intuitive to many users than F2 is.
<igDP:XamDataGrid PreviewKeyDown="xamDataGrid1_PreviewKeyDown" Name="xamDataGrid1" ... />
and in the code behind for that event:
private void xamDataGrid1_PreviewKeyDown(object sender, KeyEventArgs e) { // Allow the Enter and Spacebar keys to enter edit mode as well (in addition to the default F2 key). if (!xamDataGrid1.ActiveCell.IsInEditMode) { if (e.Key == Key.Enter || e.Key == Key.Return || e.Key == Key.Space) { Dispatcher.BeginInvoke(new Action(() => { CellValuePresenter.FromCell(xamDataGrid1.ActiveCell).Editor.StartEditMode(); } ), System.Windows.Threading.DispatcherPriority.Background, null); } } }
Awesome, thanks so much Stefan! That is exactly what I was looking for.
For those who don't want to download the source code project Stefan posted, the relevant code is:
<igDP:XamDataGrid CellActivated="xamDataGrid1_CellActivated" PreviewKeyDown="xamDataGrid1_PreviewKeyDown" Name="xamDataGrid1" ... />
and in the code behind
private void xamDataGrid1_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Right || e.Key == Key.Left || e.Key == Key.Up || e.Key == Key.Down) xamDataGrid1.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges); } private void xamDataGrid1_CellActivated(object sender, Infragistics.Windows.DataPresenter.Events.CellActivatedEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { CellValuePresenter.FromCell(e.Cell).Editor.StartEditMode(); } ), System.Windows.Threading.DispatcherPriority.Background, null); }
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
I took a look at the post provided in the answer and tried implementing it, but it did not do what the original post asks which is how to have the cell be editable just by typing on a cell; rather than having to press F2. Can you please clarify what exactly the solution to this is, and give a code sample please. Thanks.