WPF DataGrid SelectionChanged event cancelation cell focus issue?

Prevent the loop. Void OnSelectionChanged(Object sender, SelectionChangedEventArgs e) { // condition code if (conditionFailed) { datagrid. SelectionChanged -= OnSelectionChanged; datagrid.

Selectedindex = e. Removeditem0; datagrid. SelectionChanged += OnSelectionChanged; } }.

Registering or Unregistering the OnSelectionChanged() do nothing. Even if you unregister the datagridSelectionchanged event it will no doubt won't take the control to the OnSelectionChanged(Object sender, SelectionChangedEventArgs e) but it will still the change the focus on the cell clicked , the problem is how to restrict change in focus – Hemant Bhatt Nov 18 at 8:57 1 @HemantBhatt: you mentioned "I've tried to set the datagrid. Selectedindex=e.

Removeditem0 which leads the control again into selection changed event thus by putting into a continuous loop". This seems to imply that the problem with this approach is continuous loop. Unregistering, selecting, registering would seem to circumvent continuous loop issue.

– jberger Nov 18 at 15:42 here is my code private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!IsDirty) { if (e.AddedItems. Count > 0) { SelectedProfile = e. AddedItems0 as profile; } if (e.RemovedItems.

Count > 0) { } } else { MessageBox. Show("Save the profile selected", MessageBoxButton. OK, MessageBoxImage.

Warning); return; } } – Hemant Bhatt Nov 21 at 9:07 if the user has changed some thing in the selected profile and isDirty flag is set to true I want the message box to display "save the profile selected" which it is doing and the datagrid focus should remain at the profile selected earlier not to the cell which cause this event to fire – Hemant Bhatt Nov 21 at 9:12 Used DataGrid.Dispatcher.BeginInvoke() in the selection changed event the previous cell is highlighted as desired but the cell clicked becomes editable – Hemant Bhatt Nov 28 at 4:36.

Solved my problem. What need to be done was to enable the dirty flag at textbox_PreviewKeyDown() event and then performing the dirty check at datagrid_PreviewMouseLeftButtonDown() event. If dirty is found set then setting e.

Handled=true so that control skips code execution for this flow.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions