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

Row Validation & Row Details

13 Answers 371 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andreas Kägi
Top achievements
Rank 1
Andreas Kägi asked on 10 Dec 2009, 02:01 PM
hello,
I have a grid with row validation and row details. Now I experience the problem that the RowValidating-event is not raised when the user changed something in the row details. In my case, I have a check box whose IsChecked property is data-bound to a property of the row's item. The problem occurs with "internal" row details as well as with an "external" DetailsPresenter.
How can I get the GridView to raise the RowValidating-event in this case?

many thanks,
Andreas

13 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 10 Dec 2009, 03:35 PM
Hi Andreas Kägi,

RowDetails are defined by the developer (in this case you) and they work directly on the corresponding business object (the DataContext of each GridViewRow, i.e. each data item).

In this aspect RowDetails are really "external" for RadGridView because we don't know what are you going to place inside them. Only values edited through GridViewCells undergo validation, because GridViewCells are our classes (Telerik's). RowDetalsTemplate on the other hand may contain *anything* -- grids, tree-views, third-party controls, anything that can be placed inside a Silverlight DataTemplate, you name it, since RowDetails is defined by you and we have absolutely no clue about what is inside.

We simply set the correct DataContext on the DetailsPresenter control hosting your template so that the Bindings you have defined inside your RowDetailsTemplate will work on the respective data item. Having cleared this out, if you need validation inside the RowDetails template, it is up to you to provide it, since we have no idea about what will be inside the DataTemplate you have created.

I hope I managed to explain the whole mechanism. Please, let me know if I could not.

All the best,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Andreas Kägi
Top achievements
Rank 1
answered on 10 Dec 2009, 03:43 PM
Thank you for your quick answer, Ross. Your explanation sounds reasonable.
My intent was to create a Master-Detail scenario, where the grid (master) only allows navigation to
the next item (change the child), when the row'sitem validates.
Please let me know if there is an easy way to achieve this using the row validation or another mechanism.

- Andreas
0
Rossen Hristov
Telerik team
answered on 11 Dec 2009, 12:09 PM
Hello Andreas Kägi,

In this case you can place another RadGridView inside the RowDetailsTemplate and let this child grid validate the child items. I have explained how to achieve this in my blog post How To: Display Hierarchical Data with Row Details (RadGridView for Silverlight). I hope this helps.

Sincerely yours,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jonx
Top achievements
Rank 2
answered on 06 Jul 2010, 03:24 AM
Hello Ross and Andreas,
I got a similar problem.

Like you say I got lots of stuff in my row detail and I understand it is my responsibility. Granted.

Juts the thing that is still needed from your grid is an event that occurs before the row moves to the next one so that I get a chance to make sure everything is valid in my detail and if it is not, cancel the move to the next row.

How can I do that? Something like a RowChanging event and the possibility to cancel the move...

Also, how do I access the row detail content from "outside" the grid? Can the RowDetailsProvider give me access to it?

To give you more insight to my problem, I have a DataForm (beside other things) somewere in my row details that is bound to the current context. The problem comes when I change the selection to another row while my dataform has validation errors... There I get an exception from my DataForm because I need first to Commit the changes in my form before moving on (I have probably other issues because I misuse the RIA WCF services stuff I'm using, but with such an even I could deal with it)...

I know there is SelectionChanged but this comes too late. I must have missed the event because this RowChanging and more probably SelectionChanging or even DetailsRowChanging seems like common use... But then I searched the forum and I may prove wrong.

In all cases *I* need them...

any help would be much appreciated,
Thanks a lot in advance,
John.



0
Rossen Hristov
Telerik team
answered on 06 Jul 2010, 08:41 AM
Hi John,

You mention that you have a DataForm inside the RowDetailsTemplate. Probably you should attach to one of its events like ItemEditEnding, ItemEditEndedValidatingItem, or LostFocus and do the house keeping there.

You may also try attaching to RadGridView's RowDetailsVisibilityChanged event. When you select a new row and the row details of the old row become invisible this event will be fired twice. The first time it will be fired for the row details that are being hidden. You can read this information from the EventArgs. The second time it will be fired for the new row details that become visible. You can read that from the EventArgs as well. Again, I am not sure that this event will not be too late for the DataForm, which is another reason to try to resolve the issue with one of the DataForm's events.

Even if we hypothetically create the event that you want -- it will be "too late" like the SelectionChanged  event, so this will not help at all.

Using this event might help you, but in my opinion it should be the DataForm that has to be aware that it is losing focus and do the housekeeping.

If you place the same DataForm in something completely different from RadGridView, then how would you handle this same issue? Take RadGridView out of the picture and imagine that the DataForm is losing its focus for some reason. How would you handle the validation errors?

When your DataForm validation fails, you can return back to its parent row by setting the SelectedItem of the grid.

Also, you may have another option call Async Validation, which is described in great detail in this and this blog post. This is just an idea.

As for your second questions, here is an article that describes how to locate things inside the row details.

I hope this helps.

Best wishes,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonx
Top achievements
Rank 2
answered on 06 Jul 2010, 03:59 PM
Well, Ross, thank you. I appreciate your advices. They seem like the reasonable things to do...
I was a bit lost after so many time spent on that "simple" matter that I have probably missed the obvious.
I'll give it a try and let you know what it gives... Thanks again for you time and your kind insight, I'll keep you posted.
John.
0
Jonx
Top achievements
Rank 2
answered on 06 Jul 2010, 09:43 PM
Ok, I took some hours to see what other options I had and I can tell you that none of the possibilities you talked about can be used...

I understand the arguments that the DataForm should do its own housekeeping...
Just, I need that the grid gives me the possibility to do it...

Let me explain again what I have. I have a radgridview listing some customers. In the (external) detail row I have a dataform that let's me add/edit/mod the customer's address.

The scenario is that I select a customer's row. His address related property is databound to the dataform currentitem.
I modify the address for example I set azerty as a zip code. I try to submit changes using a save button foudn outside the grid. The dataform validation fails and the data are not submitted. That all is correct.

Now, with the dataform still displaying the errors I click on another row in the grid...  Here the dataform fires an exception because I try to change the current item (because the databinding link) wheras the current item still has validation errors...

None of the dataform events are of any help... They have all already played their role or come too late or not at the good moment.

        private void addressForm_ValidatingItem(object sender, System.ComponentModel.CancelEventArgs e)
has already fired and has throw a validation exception. the validation errors are still present.
 
        private void addressForm_EditEnded(object sender, DataFormEditEndedEventArgs e)
        private void addressForm_EditEnding(object sender, DataFormEditEndingEventArgs e)
did not fire because edit has not ended

        private void addressForm_LostFocus(object sender, RoutedEventArgs e)
we lost the focus earlier at validation

        private void addressForm_CurrentItemChanged(object sender, EventArgs e)
comes too late after the exception I get.

Even if I had a CurrentItemChanging event I would not be able to ask the grid not to change row in case the dataform is not valid.

You are right by telling that SelectionChanged comes too late but I'm pretty sure now that my solution would be to have a SelectionChanging event that would allow me to cancel the row selection change before it happens.

If I had that event I could either check if that dataform.IsValid and if it not the case I would e.Cancel = true;
Also, I could eventually clear the dataform validation errors if I wanted because in that case the dataform doens't mind to move to another currentitem (note that I did not bind a list of addresses but only one address to the currentitem)

So, clearly, I think that it is the grid's role to let me cancel a row selection change, not the dataform's role to move back to its parent.

The RowDetailsVisibilityChanged event comes too late too or too soon depending if I'm leaving or coming to the row...

As for accessing the row details, I would like to do it from outside the grid...  This would let me check the dataform validity or eventually endEdit or clean up things directly from my page's save button... 

also that would let me bind the IsEnabled of the grid to the HasValidationErrors of the dataform as this seems to be my only option left... that way I cold disable the grid as long as no movement is possible...

What do you think of that... can I have my SelectionChanging event now mister telerik? Please? 


0
Jonx
Top achievements
Rank 2
answered on 07 Jul 2010, 12:05 AM
Also note that what I'm asking is valid even if I was using something else then a dataform.

A simple text field. If it's content was not valid, I should have a way to avoid the parent row grid moving or else I would risk loosing data as the content of the field, because not valid, was not commited back to it's entity.
0
Rossen Hristov
Telerik team
answered on 07 Jul 2010, 12:34 PM
Hi John,

I totally understand your problem. There already is the same feature request and you can vote for it. Meanwhile, you can try to do something with handling the raw mouse events (after all -- they occur before anything else) when rows are being clicked, but I am not sure whether this will be trivial. To tell you the truth I really think that this will be an overkill.

As for the external DetailsPresenter, you can use Telerik's extension method ChildrenOfType<T> and find your control that is inside it by its type. Another alternative is to use the fact that the DetailsPresenter is in fact a ContentControl. The thing that was created by loading your RowDetailsTemplate will actually be the Content of this ContentControl. So if you place your own user control in the row details template, you can then cast the DetailsPresenter.Content to this type and do anything with it -- like find one of its children.

I hope this helps.

Best wishes,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonx
Top achievements
Rank 2
answered on 07 Jul 2010, 02:06 PM
Hum, I agree with you, overkill would be the correct term. I'll go for a disabled grid for now, controled by the content of my row detail.
That feature should not be hard to add. I wonder why only so little people ask about that. In my old Delphi time I think I used that event all the time...

I voted for it but I guess it's not gonna happen any time soon as there is only one vote: mine ;)
Eventually I'll go for the source included if available, once I buy the library.

For the detail presenter, thank you, it's working.

Thank you for your time Ross,
 See you around,
John.
0
Rossen Hristov
Telerik team
answered on 09 Jul 2010, 08:40 AM
Hello John,

We will do our best to implement this as soon as possible. Please, excuse us for the inconvenience that this might be causing you.

Regards,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Myth
Top achievements
Rank 1
answered on 25 May 2011, 07:48 AM
I would actually prefer if it were possible to manually call the ValidateRow method, so I can present the user with a nice red row and error message. An invalidated row will also disable the user to change the row.
0
Nedyalko Nikolov
Telerik team
answered on 25 May 2011, 03:25 PM
Hi Myth,

Indeed you cannot call row validation method from outside. We will reconsider this case, but I cannot commit that we will make it possible. 

However there is a simple workaround. All row related editing events like RowValidating, RowValidated and RowEditEnded are thrown for the row in edit mode (so you need row in edit mode you will recognize it with a small edit indicator at the beginning of the row) and a current cell inside this row. Row events will get fired when current cell is moved to another row. Note that it is not necessary initial current cell to be in edit mode (if it is in edit mode also cell related editing events will be raised).
Let me know if this doesn't help.

Kind regards,
Nedyalko Nikolov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Andreas Kägi
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Andreas Kägi
Top achievements
Rank 1
Jonx
Top achievements
Rank 2
Myth
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or