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

Updating child table data in RadGridView and ADO.Net Data Services

4 Answers 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 17 Jun 2009, 11:34 AM
Hi

I have a RadGridView which is bound to a custom object with a child custom object using the method described in GridView>Hierarchy>PropertyHierarchy example and have specified the columns in code.

I'm data binding to ADO.Net Data Services and using OpenAccess.

I can't seem to find an example of inserting or updating a value in the child grid anywhere - I have two columns - one text editor and one as a combobox editor.  I assume I need to handle an event top update the data source, yet cannot determine which are fired.

Can anyone provide guidance on how to do this.

Thanks in advance

Ian

4 Answers, 1 is accepted

Sort by
0
Hristo Deshev
Telerik team
answered on 18 Jun 2009, 01:51 PM
Hi Ian,

I used this blog post as a starting point -- it edits data using RadGridView for Silverlight and OpenAccess over an ADO.NET data service. I just had to add hierarchy to the equation :-). I did that in a somewhat clumsy way -- I linked Customers to Suppliers using the Country field. It may not be the most meaningful hierarchy ever, but, hey, it works!

I hit a problem when I tried to subscribe to the RowEditEnded event -- the event is declared on the GridViewDataControl class, and you have to find the respective hierarchy child, when it loads, and attach to its event. I had to use a little hack to accomplish that -- I found the expander element in the row, and handled its Expanded event. I attach to the RowEditEndedEvent bit after the event fires:

void gridView_RowLoaded(object sender, RowLoadedEventArgs e) 
    var expander = e.Row.ChildrenOfType<RadExpander>().FirstOrDefault(); 
    if (expander != null
    { 
        expander.Expanded += expander_Expanded; 
    } 
 
void expander_Expanded(object sender, RoutedEventArgs e) 
    this.Dispatcher.BeginInvoke(() => { 
                                    var dataControl = 
                                        ((FrameworkElement) sender).ChildrenOfType<GridViewDataControl>().First(); 
                                    dataControl.RowEditEnded += gridView_RowEditEnded; 
                                }); 

Our Q2 release will expose a public event that will get fired whenever a hierarchy child gets expanded, and the hack above will not be necessary.

Regards,
Hristo Deshev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ian
Top achievements
Rank 1
answered on 19 Jun 2009, 10:32 PM
Thanks Hristo, I can see why I was struggling!

I can now see that the expand event is firing.  However I'm using a property hierarchy - binding the grid with a list of objects List<OUGroup> that contains a property of type List<OrganisationalUnit> which binds to the child grid automatically. 

When I run the code, the expander_Expanded event handler is unable to find any children of type <GridViewDataControl>. 

My code to create the table is:

GridViewTableDefinition

 

detailDefinition = new GridViewTableDefinition();

 

detailDefinition.AutoGenerateFieldDescriptors =

false;

 

 

var ouNameColumn = new GridViewDataColumn();

 

ouNameColumn.UniqueName =

"OUCode";

 

ouNameColumn.HeaderText =

"OU Name";

 

ouNameColumn.DataType =

typeof(string);

 

 

detailDefinition.Relation =

new PropertyRelation("OrganisationalUnits");

 

detailDefinition.FieldDescriptors.Add(ouNameColumn);

 

 

this.RadGridViewOUGroup.TableDefinition.ChildTableDefinitions.Add(detailDefinition);

I've also tried autogenerating the fields, but the same happens.

I'd be grateful of any further help you can provide.  Thanks.

Kind regards

Ian

 

0
Hristo Deshev
Telerik team
answered on 22 Jun 2009, 10:31 AM
Hello Ian,

Are you using the code from my sample project? I too do not get any GridViewDataControl children in the expanded event -- those controls get generated when the child templates get applied, and that happens a bit "later". That is why, I pushed the code that searches for those controls at the back of the Dispatcher queue, using BeginInvoke:

void expander_Expanded(object sender, RoutedEventArgs e) 
    this.Dispatcher.BeginInvoke(() => { 
                                    var dataControl = 
                                        ((FrameworkElement) sender).ChildrenOfType<GridViewDataControl>().First(); 
                                    dataControl.RowEditEnded += gridView_RowEditEnded; 
                                }); 
 

That fixed the problem for me and discovered the generated data controls

Greetings,
Hristo Deshev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ian
Top achievements
Rank 1
answered on 07 Jul 2009, 06:06 PM
Hi Hristo,

Thanks again for your help.  Apologies for slow response, have been on leave and then catching up.

I've double checked that my code is the same, and it is the same as far as I can see.

The only clue I have is that the  expander_Expanded event fires four times when the node is expanded and throws errors on the final two only.

Seeing as the new release is now available, I'll give that a go and we'll see how I get on.

Kind regards

Ian
Tags
GridView
Asked by
Ian
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
Ian
Top achievements
Rank 1
Share this question
or