I need to tab into a xamDataGrid, which would already have the active cell set on a combobox editor, and have that cell go into edit mode upon entry. I've discovered this is not as simple as calling StartEditMode on the CellValuePresenter in GotFocus, as that caused the event to be called multiple times when moving between grid rows, and I ended up breaking the event model. Has anyone been able to do this successfully without breaking all the standard navigation built into xamDataGrid?
Hello Darryl,
Thank you for your post!
I have been looking into your question. When a Cell of the XamDataGrid is activated the CellActivated event of the XamDataGrid is fired. Using this event you can force the cell, that is currently active to enter in edit mode.
Here is a code snippet, that you can use:
Dispatcher.BeginInvoke(new Action(() =>
{
CellValuePresenter.FromCell(e.Cell).Editor.StartEditMode();
}
), System.Windows.Threading.DispatcherPriority.Background, null);
I have also created a small sample application for you to show you this functionality. In the attached sample application you have to click on the first cell, in order to activate it. Then by pressing the Tab key you would navigate through the cells and they will enter in edit mode.
Please find the attachment and feel free to let me know if you have any further questions on this matter.
Thank you, but this is not what I asked. I need to tab into the grid and have the active cell go into edit mode. Do you know someone else who might be able to help?
The problem with this suggestion, and as was the case yesterday when I experimented with the CVP GotFocus event, is the code breaks the functionality of normal keyboard navigation to other cells once you are in the grid.
I have been looking into your post. After working on the functionality that you are trying to achieve and doing some research, this functionality has been determined to be a new product idea. You can suggest new Product Ideas for future versions (or vote for existing ones) at http://ideas.infragistics.com.
Steps to create your idea:
1. Log into the Infragistics Product Ideas site at http://ideas.infragistics.com (creating a new login if needed).
2. Navigate to the product / platform channel of your choice (e.g. WPF, Windows Forms, ASP.NET, HTML5 / Ignite UI, iOS / NucliOS, etc.)
3. Add your product idea and be sure to be specific and provide as much detail as possible.
• Explain the context in which a feature would be used, why it is needed, why it can’t be accomplished today, and who would benefit from it. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it. Be convincing!
• [CASE: “Reference case [case number], FORUMS: “Include a link to this thread”] in your idea so product management will be able to look back at this case.
The benefits of submitting the product idea yourself include:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
Additional benefits of the Product Idea system include:
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
The product ideas site allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Thank you for contacting Infragistics.
I am just checking if you have any further questions on this matter. Please do not hesitate to let me know if you do.
Hi Gergana. Thanks for checking. Unfortunately, the solution seems a bit crude, but here's the code I'm using based on some additional help from Rob (sorry I don't have time to format prettier, but at least this doesn't truncate lines). Basically you can only start edit mode if the grid was previously unfocused, otherwise you break things:
public class XamDataGridTabBehavior : Behavior<XamDataGrid> { Window window; bool gridFocused;
protected override void OnAttached() { base.OnAttached();
AssociatedObject.InitializeTemplateAddRecord += XamDataGrid_InitializeTemplateAddRecord; AssociatedObject.Loaded += AssociatedObject_Loaded; AssociatedObject.Unloaded += AssociatedObject_Unloaded; }
void XamDataGrid_InitializeTemplateAddRecord(object sender, InitializeTemplateAddRecordEventArgs e) { e.TemplateAddRecord.Cells[1].IsActive = true; // activate first editable cell in add record for tabbing into grid }
void AssociatedObject_Loaded(object sender, RoutedEventArgs e) { window = UIUtils.FindVisualParent<Window>(AssociatedObject); window.PreviewGotKeyboardFocus += window_PreviewGotKeyboardFocus; }
void AssociatedObject_Unloaded(object sender, RoutedEventArgs e) { window.PreviewGotKeyboardFocus -= window_PreviewGotKeyboardFocus; }
void window_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { if (e.OriginalSource == AssociatedObject && !gridFocused) { if (AssociatedObject.ActiveCell != null) Dispatcher.BeginInvoke(new Action(() => AssociatedObject.ExecuteCommand(DataPresenterCommands.StartEditMode))); gridFocused = true; } else { var grid = UIUtils.FindVisualParent<XamDataGrid>(e.OriginalSource as UIElement); if (grid != AssociatedObject) gridFocused = false; } } }
Thank you for the feedback. I am glad, that you have found a solution to your issue. Please do not hesitate to let me know if you have any further questions on this matter.