I'm using XamDataGrid in a MVVM WPF project. I've bound the ActiveDataItem to the CurrentBook property in my ViewModel. Double clicking a record (book) in the XamDataGrid opens another window in which to edit it. The window's data context is the same ViewModel as the XamDataGrid's and the text boxes in the "editor" window are bound to the CurrentBook property. All editing and saving works fine.
I also have several buttons in the editor window that are bound to the "RecordAbove" and "RecordBelow" commands so you can scroll through the list from the editor window. This also works fine with the XamDataGrid's ActiveDataItem automatically updating the viewmodel which in turn automatically updates the editor window.
Here is my problem. Let's say I double click book number 21 in the XamDataGrid. The editor opens with 21 loaded. Now I scroll to book number 23 using the RecordBelow command several times. Everything looks great at this point. The XamDataGrid has the correct record selected etc. I can even make changes to book 23 and save them. But, when I close the editor window, the ActiveDataItem of the XamDataGrid automatically resets to book number 21 and both 21 and 23 are selected even though I've set SelectionTypeRecord="Single"
What I really want, is to exit the editor window and simply have book 23 as the ActiveDataItem with nothing else selected.
Any Ideas?
Thank you for your help. I agree that it isn't a bug after all...
Hello StillLearnin ,
Our developers have completed their review of development issue 113953. They have determined that the behavior that you are referring is not caused by an issue in our control. The reason that the original record is re-activated after the dialog is dismissed is because that RecordPresenter had focus when the modal dialog was shown. Therefore, when the dialog is closed the original record presenter is re-focused which causes it to become the ActiveRecord again.
To work around this behavior simply set focus to the xamDataGrid before showing the dialog, e.g.:
if (cvp != null)
{
xamDataGrid1.Focus();
LaunchBookEditor();
}
Please let me know if you need any additional assistance with this.
It's a bit of a work around but it does work. I'll use it for now and await further developments from the development team :)
Thanks for your help!
While our developers review this issue I can suggest you just save the active record in the handler of the closing event of the window and reset it in the Closed:
private void LaunchBookEditor() { BookEditor MyBookEditor = new BookEditor(MyViewModel, xamDataGrid1); MyBookEditor.Owner = Window.GetWindow(this); MyBookEditor.Closing += new System.ComponentModel.CancelEventHandler(MyBookEditor_Closing); MyBookEditor.Closed += new EventHandler(MyBookEditor_Closed); MyBookEditor.ShowDialog(); } Record active; void MyBookEditor_Closing(object sender, System.ComponentModel.CancelEventArgs e) { active = xamDataGrid1.ActiveRecord; } void MyBookEditor_Closed(object sender, EventArgs e) { xamDataGrid1.ActiveRecord = active; }
Hello,
Thank you for the sample and all of the details. I investigated this issue and I asked our developers to research it further so I submit this as issue in our in our internal tracking system with a Development ID of 113953 and I created a support ticket for you with number CAS-92752-YYL6T9. I will provide you with more details on this through the support ticket.
Thank you for reporting this to us.