This is a migrated thread and some comments may be shown as answers.

Block changing row while editing

7 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bert
Top achievements
Rank 1
Bert asked on 04 Oct 2013, 12:29 PM

Hello,

We want to be able to block a row change when a user is editing a row and clicks on a different row in the RadGridView.

We have noticed that the RowValidating, RowValidated and RowEndEdit events are fired before the SelectionChanging event. This sounds logical but how can we see in RowValidating that the event is fired due to selecting an different row?

Kind regards,

Bert

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 08 Oct 2013, 11:04 AM
Hi Bert,

Once you click outside of the row currently being edited, the row will try to commit. Therefore the events: RowValidating, RowValidated and RowEndEdit will be raised.  Once the commit is successful, the row where you have clicked on will be selected.

The RowValidating will be raised if you click outside of the row currently being edited, it will not be raised if you click on a different cell in the same row.

May I ask you to share why do you need to know if the event is fired due to selecting a different row?

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Bert
Top achievements
Rank 1
answered on 08 Oct 2013, 12:12 PM
Hello Didie,

this is an end user requirement; the application must ask to commit or rollback the changes when a user clicks on another row.

Kind Regards,
Bert


0
Dimitrina
Telerik team
answered on 09 Oct 2013, 08:51 AM
Hello Bert,

Generally there is not a way to know what action invoked the commit. That is why I am trying to understand the exact business scenario you have. 
Are there cases when the RowValidating event will be raised but you do not want to show the confirm message before the commit?

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Bert
Top achievements
Rank 1
answered on 09 Oct 2013, 09:21 AM
Hello Didie,

the conformation question should only be shown when the user clicks on another row in the grid.
When the user presses the enter key the data must be committed and the selection must stay on the current row (EnableLostFocusSelectedState = false). In this case we do not want to show the conformation question.
The same when the user presses the save button.

So we just need to know the whether the RowValidating event was fired due to selecting another row in the grid.

Kind regards,
Bert
0
Dimitrina
Telerik team
answered on 10 Oct 2013, 07:32 AM
Hi Bert,

Thank you for clarifying your exact requirements.

To achieve your goal, you can use the following code:

private void clubsGrid_RowValidating_1(object sender, GridViewRowValidatingEventArgs e)
{
    FrameworkElement fe = FocusManager.GetFocusedElement(FocusManager.GetFocusScope(e.Row.GridViewDataControl)) as FrameworkElement;
    GridViewRow focusedRow = fe.ParentOfType<GridViewRow>();
    if (focusedRow != null
      && !object.Equals(e.Row.DataContext, focusedRow.DataContext)
      && object.Equals(e.Row.GridViewDataControl, focusedRow.GridViewDataControl))
    {
        MessageBox.Show(string.Format("RowValidating is fired due to click on another row!"));
    }
}
 
I hope this helps.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Bert
Top achievements
Rank 1
answered on 15 Oct 2013, 06:15 AM

Hello Didie,

I tried it but it does not seems to work. 

FrameworkElement fe = FocusManager.GetFocusedElement(FocusManager.GetFocusScope(e.Row.GridViewDataControl)) as FrameworkElement;
This line of code returns the RadGridView control as FrameWorkElement fe.

GridViewRow focusedRow = fe.ParentOfType<GridViewRow>();
This line returns null.

ParentOfType gets the parent element from the visual tree by given type. I guess it tries to find a parent of the type GridViewRow wich does not exist because it is a child of the GridView and not a parent.

Secondly, there is also another requirement which I forgot to mention. If the user clicks on another row while editing, the application must ask ‘Do you want to save you changes’ (Yes, No, Cancel).

Yes: commit and continue, No: rollback and continue, Cancel: stay on the row that is being edited.


I forced GridViewRowValidatingEventArgs.IsValid to false in RowValidation to test the cancel situation. If I do so the edited row shows an error marker and the selection moves to the row that was clicked. This is not what we want, the selection must stay on the row that is being edited and the grid should not show an error marker.


Kind regards,

Bert



    
0
Dimitrina
Telerik team
answered on 15 Oct 2013, 08:37 AM
Hi Bert,

I have attached a test project demonstrating the code I suggested. The focusedRow is the row you clicked on, it is not null.

As to the selection - you should cancel it if the user cancels the commit.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Bert
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Bert
Top achievements
Rank 1
Share this question
or