Hi there,
I have 2 RadGridViews in a sample project defined as per the attached screenshot (GridViewFocusIssue.png).
The crux of the issue is as follows:
-If I edit any of the cells in the 1st grid, and then click on either the TextBox or the Button, then the Cell Edit is committed as expected.
-If I edit any of the cells in the 1st grid, and then click into a cell in the 2nd grid, the cell that was being edited in the 1st grid doesn't leave Edit mode. (please see ProblemScreenshot.png)
My desired behaviour is that as soon as a user clicks outside of a cell that is in edit mode, then that cell should have its edit committed.
Please can you advise how to do this?
6 Answers, 1 is accepted
I should add that I am on the 2012.3 version of the libraries.
As an experiment, I have I tried the 2015 trial and the behaviour is as I expect, so I assume this was a bug that was fixed.
Upgrading is currently not an option for us, so please can you suggest a workaround?
Thanks
Can you try calling CommitEdit() method of the first grid once the focus is no the other ? Does this resolve the issue ?
Regards,
Maya
Telerik
Hi Maya,
I suppose I could and yes it does solve the issue, however it would require every RadGridView in my application to know about every other RadGridView, which is not feasible.
You can try adding handlers for LostFocus and GotFocus events and implement the logic once they are fired. It might be something as follows:
RadGridView gridView;
public MainWindow()
{
InitializeComponent();
this.AddHandler(RadGridView.GotFocusEvent, new RoutedEventHandler(OnGotFocus), true);
this.AddHandler(RadGridView.LostFocusEvent, new RoutedEventHandler(OnLostFocus), true);
}
private void OnGotFocus(object sender, RoutedEventArgs e)
{
var focusedElement = e.OriginalSource as FrameworkElement;
var parentGrid = focusedElement.ParentOfType<
RadGridView
>();
if (this.gridView != null && parentGrid != null && !this.gridView.Equals(parentGrid))
{
this.gridView.CommitEdit();
this.gridView = null;
}
}
private void OnLostFocus(object sender, RoutedEventArgs e)
{
var element = e.OriginalSource as FrameworkElement;
if (element != null)
{
var parentGrid = element.ParentOfType<
RadGridView
>();
this.gridView = parentGrid != null ? parentGrid : null;
}
}
Regards,
Maya
Telerik
May you explain your logic?
I don't think it can work as the OriginalSource in the OnLostFocus event is always going to be the same local grid.
My idea was to save which instance of RadGridView is the one that loses the focus and if another one gets it, to commit the changes of the first one.
Please give it a try and let me know how it goes.
Regards,
Maya
Telerik