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

RadGridView Master Detail Save Issue

14 Answers 251 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Monte Baker
Top achievements
Rank 2
Monte Baker asked on 02 Jun 2010, 04:55 PM
I am currently working with a page (Vendor) a RadGridView (VendorGrid)in Silverlight 3 that has a child grid (VendorContacts) located in a radtab control.  I am trying to invoke CRUD methods from a RibbonBar control located on the ParentPage (mainpage)  i have achieved success with the save function when it is called from a button inside the itemdetials section of the vendor grid, however when I call the function from the parent page i am unable to get an object reference to the VendorContacts.  as the only difference that I can tell is that the button includes (object sender, RoutedEventArgs e) which as far as i know are not used, i am at a loss as to what I am doing wrong.

<navigation:Page x:Class="EntityBackOffice2010_R1.VendorGridMain" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
    xmlns:grid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 
    xmlns:tnavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
    xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"   
    xmlns:telerikData="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" 
    mc:Ignorable="d" 
    d:DesignWidth="1000" d:DesignHeight="600">  
    <Grid Background="Black">  
        <Border Background="Transparent" BorderBrush="#7FFFFFFF" BorderThickness="1" CornerRadius="3" Margin="3">  
            <Grid Background="#FFD7E1E4">  
                <Grid.RowDefinitions> 
                    <RowDefinition /> 
                </Grid.RowDefinitions> 
                <grid:RadGridView Grid.Row="0"   
                x:Name="VendorGrid"   
                ItemsSource="{Binding}" 
                Background="Transparent" 
                AlternationCount="2" 
                AlternateRowBackground="#FFE1E6E3" 
                Margin="5" 
                RowDetailsVisibilityMode="VisibleWhenSelected" 
AddingNewDataItem="VendorGrid_AddingNewDataItem" 
RowEditEnded="VendorGrid_RowEditEnded"   
                ColumnWidth="*" 
                DataLoadMode="Asynchronous"   
                IsReadOnly="False"   
                AutoGenerateColumns="False"   
                CanUserFreezeColumns="False"    
                CanUserResizeColumns="False"   
                CanUserDeleteRows="False"   
                CanUserInsertRows="True"   
                ShowGroupFooters="False" 
                ShowGroupPanel="False" 
                RowIndicatorVisibility="Collapsed">       
                    <grid:RadGridView.Columns> 
                        <grid:GridViewDataColumn Header="ID"            DataMemberBinding="{Binding VendorID}" IsReadOnly="True" /> 
                        <grid:GridViewDataColumn Header="Company Name"  DataMemberBinding="{Binding VendorName, Mode=TwoWay}" IsReadOnly="True" /> 
                        <grid:GridViewDataColumn Header="Description"   DataMemberBinding="{Binding Description, Mode=TwoWay}" Width="*" IsReadOnly="True" /> 
                        <grid:GridViewDataColumn Header="Manager"       DataMemberBinding="{Binding Manager, Mode=TwoWay}" IsReadOnly="True" /> 
                        <grid:GridViewDataColumn Header="City"          DataMemberBinding="{Binding PCity, Mode=TwoWay}" IsReadOnly="True" /> 
                        <grid:GridViewDataColumn Header="State"         DataMemberBinding="{Binding PState, Mode=TwoWay}" IsReadOnly="True" /> 
                        <grid:GridViewDataColumn Header="Phone"         DataMemberBinding="{Binding Phone, Mode=TwoWay}" IsReadOnly="True"/>  
                    </grid:RadGridView.Columns> 
                    <grid:RadGridView.RowDetailsTemplate> 
                        <DataTemplate x:Name="VendorDetailsTemplate">  
                            <StackPanel Orientation="Vertical" Margin="0" Grid.Row="0">  
                                <tnavigation:RadTabControl x:Name="VendorDetailsTemplateTabCTRL" BackgroundVisibility="Visible" Margin="0,0,0,0" VerticalAlignment="Top" Background="Transparent" controls:StyleManager.Theme="Office_Black">  
                                    <tnavigation:RadTabItem Header="Contacts">  
                                        <Border BorderBrush="#FF848484" BorderThickness="0,1,0,0">  
                                        <grid:RadGridView   
                                            x:Name="VendorContactsGrid"   
                                            DataContext="{x:Null}"   
                                            ShowGroupPanel="False" 
                                            Margin="15" 
                                            Loaded="VendorContacts_Loaded"   
                                            AutoGenerateColumns="False">  
                                            <grid:RadGridView.Columns> 
                                                <grid:GridViewDataColumn Header="Title"     DataMemberBinding="{Binding Title, Mode=TwoWay}"/>  
                                                <grid:GridViewDataColumn Header="FirstName" DataMemberBinding="{Binding FirstName, Mode=TwoWay}" /> 
                                                <grid:GridViewDataColumn Header="LastName"  DataMemberBinding="{Binding LastName, Mode=TwoWay}"/>  
                                                <grid:GridViewDataColumn Header="Phone"     DataMemberBinding="{Binding Phone, Mode=TwoWay}"/>  
                                                <grid:GridViewDataColumn Header="Fax"       DataMemberBinding="{Binding Fax, Mode=TwoWay}"/>  
                                                <grid:GridViewDataColumn Header="Email"     DataMemberBinding="{Binding Email, Mode=TwoWay}"/>  
                                                <grid:GridViewDataColumn Header="Active"    DataMemberBinding="{Binding Active, Mode=TwoWay}"/>  
                                            </grid:RadGridView.Columns> 
                                        </grid:RadGridView> 
                                        </Border> 
                                    </tnavigation:RadTabItem> 
                                </tnavigation:RadTabControl> 
                                <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="2" Margin="5,5,5,5" HorizontalAlignment="Right">  
                                    <controls:RadButton Height="25" Margin="5" Content="NEW" Click="addVendorBtn_Click" FontSize="10" Width="75" controls:StyleManager.Theme="Office_Black"/>  
                                    <controls:RadButton Height="25" Margin="5" Content="SAVE" Click="saveVendorChanges_Click" FontSize="10" Width="75" controls:StyleManager.Theme="Office_Black"/>  
                                    <controls:RadButton Height="25" Margin="5" Content="DELETE" FontSize="10" Width="75" controls:StyleManager.Theme="Office_Black"/>  
                                    <controls:RadButton Height="25" Margin="5" Content="CANCEL" FontSize="10" Width="75" controls:StyleManager.Theme="Office_Black"/>  
                                </StackPanel> 
                            </StackPanel> 
                        </DataTemplate> 
                    </grid:RadGridView.RowDetailsTemplate> 
                </grid:RadGridView> 
            </Grid> 
        </Border> 
    </Grid> 
</navigation:Page> 


    //Called from Parent RibbonBar   
        public void saveVendor()  
        {  
            Vendor v = this.VendorGrid.SelectedItem as Vendor;  
            VendorContact vc = this.VendorContactsGrid.CurrentItem as VendorContact;  
            svcContext.UpdateObject(v);  
            svcContext.UpdateObject(vc);  
            svcContext.BeginSaveChanges(SaveChangesOptions.Batch, OnVendorChangesSaved, v);  
 
        }  
    //Called from Button in ItemDetails of VendorGrid  
        public void saveVendorChanges_Click(object sender, RoutedEventArgs e)  
        {  
            Vendor v = this.VendorGrid.SelectedItem as Vendor;  
            VendorContact vc = VendorContactsGrid.CurrentItem as VendorContact;  
            svcContext.UpdateObject(v);  
            svcContext.UpdateObject(vc);  
            svcContext.BeginSaveChanges(SaveChangesOptions.Batch, OnVendorChangesSaved, v);              
        } 

14 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 02 Jun 2010, 05:14 PM
Hi Monte Baker,

 As far as I understand, you have defined you RibbonBar in a separate XAML file, right? So your saveVendor() method (the first one) is not in the VendorGridMain, correct? If I'm not wrong, when you press the save button in your ribbon, the button click handler (or command, for MVVM), is trying to access the two grids in the VendorGridMain page.

Please let me know a bit more about your scenario, especially the location of the two save methods, and I shall endeavor to assist you further.

Regards,
Yavor Georgiev
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
Monte Baker
Top achievements
Rank 2
answered on 02 Jun 2010, 05:36 PM
Both of the above methods are located in VendorGridMain.xaml  I am calling the savevendor from mainpage.xaml which contains a ribbonbar and navigation frame by the method below.
        private void SaveVendorClick(object sender, RoutedEventArgs e)  
        {  
            VendorGridMain vendorPG= new VendorGridMain();  
            vendorPG.saveVendor();  
        } 
0
Yavor Georgiev
Telerik team
answered on 04 Jun 2010, 10:05 AM
Hi Monte Baker,

 First of all, let me apologize for the delayed response.

I bring good news, however. I've managed to create a sample project based on your input that successfully demonstrates how to call a method from the main page in a navigated frame.
Please inspect the solution and let me know if you need any further assistance.

Kind regards,
Yavor Georgiev
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
Monte Baker
Top achievements
Rank 2
answered on 04 Jun 2010, 02:42 PM
I like the solution, however I am getting a strange error when I try to implement in my solution.

The call is ambiguous between the following methods or properties: 'Telerik.Windows.Controls.DependencyObjectExtensions.FindChildByType<Telerik.Windows.Controls.RadGridView>(System.Windows.DependencyObject)' and 'Telerik.Windows.Controls.DependencyObjectExtensions.FindChildByType<Telerik.Windows.Controls.RadGridView>(System.Windows.DependencyObject)' 

Below are my namespaces and the attached block of code that is erroring.

using System;  
using System.Windows;  
using System.Windows.Controls;  
using System.Windows.Documents;  
using System.Windows.Ink;  
using System.Windows.Input;  
using System.Windows.Shapes;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.Data.Services.Client;  
using System.Collections.ObjectModel;  
using System.Collections.Specialized;  
using System.Text;  
using System.Windows.Data;  
using Telerik.Windows.Data;  
using System.ComponentModel;  
using System.Data;  
using System.Collections;  
using Telerik.Windows.Controls.GridView;  
using Telerik.Windows.Controls;  
using System.Globalization;  
using EntityBackOffice2010_R1.EntityServiceReference; 

The error is coming from the specific "var contactsGrid = row.FindChildByType<RadGridView>(); " in the saveVendor function

public void saveVendor()  
{  
    var vendor = this.VendorGrid.SelectedItem as Vendor;  
    var row = this.VendorGrid.ItemContainerGenerator.ContainerFromItem(vendor) as GridViewRow;  
    var contactsGrid = row.FindChildByType<RadGridView>();  
    var contact = contactsGrid.SelectedItem as VendorContact;  
    MessageBox.Show(String.Format("Saving Contact {0} of Vendor {1}", contact.FirstName, vendor.VendorName));  

I am very confused by this error as it seems that the two methods that VS are saying are ambiguous appear to be identical.
0
Yavor Georgiev
Telerik team
answered on 07 Jun 2010, 12:33 PM
Hi Monte Baker,

 I'm sorry, but I'm unable to reproduce the issue on my end. Could you please send me a sample project?

All the best,
Yavor Georgiev
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
Monte Baker
Top achievements
Rank 2
answered on 07 Jun 2010, 08:13 PM
Ok,

This has no become interesting and I am not sure if you can help, but when I copy the code from MainPage.xaml and VendorGridMain.xaml into a new project i no longer get the error, but it is still present in the original application (which is way to big to send you)  any thoughts on where this error could be coming from...
"The call is ambiguous between the following methods or properties: 'Telerik.Windows.Controls.DependencyObjectExtensions.FindChildByType<Telerik.Windows.Controls.RadGridView>(System.Windows.DependencyObject)' and 'Telerik.Windows.Controls.DependencyObjectExtensions.FindChildByType<Telerik.Windows.Controls.RadGridView>(System.Windows.DependencyObject)' views\VendorGridMain.xaml.cs 226 32 EntityBackOffice2010_R1"
0
Monte Baker
Top achievements
Rank 2
answered on 07 Jun 2010, 08:35 PM
I have resolved the error it appears that having "Telerik.Windows.Controls.DataVisualization.dll" in the resources that I was getting the error.
0
Monte Baker
Top achievements
Rank 2
answered on 07 Jun 2010, 08:44 PM
Just one more question and we can close this thread.  Is there anyway to specify the FindChildByType argument with the child name.  For example in other parts of my application I will be trying to do the same exact thing, however in those cases I may have as many as 5 child grids inside the parent.

Thanks,
0
Yavor Georgiev
Telerik team
answered on 08 Jun 2010, 08:38 AM
Hi Monte Baker,

 You need to perform a simple query. So:

var childGrids = row.FindChildByType<Grid>().Where(c => c.Name == "MyName");

Make sure to include "using System.Linq;" in your usings.

All the best,
Yavor Georgiev
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
Monte Baker
Top achievements
Rank 2
answered on 09 Jun 2010, 02:54 PM
Thank you for the response.  I have tried your suggestion but I recieve the error "'System.Windows.Controls.Grid' does not contain a definition for 'Where' and the best extension method overload 'Telerik.Windows.Data.QueryableExtensions.Where(System.Linq.IQueryable, Telerik.Windows.Data.FilterDescriptorCollection)' has some invalid arguments"

I have tried both

var

 

row = this.RecipeGrid.ItemContainerGenerator.ContainerFromItem(recipe) as GridViewRow;

 

var childGrid = row.FindChildByType<Grid>().Where(c => c.Name == "MyName");  
var childGrid = row.FindChildByType<RadGridView>().Where(c => c.Name == "MyName"); 

with success on neither option, is it my row variable that is causing this isssue.  FYI i did verify that System.Linq is in the usings.
0
Yavor Georgiev
Telerik team
answered on 09 Jun 2010, 02:58 PM
Hi Monte Baker,

 I apologize, you should use the ChildrenOfType<>() method, instead of FindChildByType<>.

Best wishes,
Yavor Georgiev
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
Monte Baker
Top achievements
Rank 2
answered on 09 Jun 2010, 03:10 PM
Thank you, that appears to have worked
0
Monte Baker
Top achievements
Rank 2
answered on 09 Jun 2010, 04:06 PM
Hopefully you can explain one more issue to me.  As mentioned above I am using this code to determine if one or more child gridview objects should be saved.  in the previous version you supplied I was using

if (row.FindChildByType<RadGridView>() != null)  
 

to determine if the child grid had been loaded and then performing a Context.UpdateObject.  With the new technique that I am using I have altered the If statement as follows

if ((row.ChildrenOfType<RadGridView>().Where(c => c.Name == "MyChild")) != null

However, this always evaluates as NOT null regarless of whether or not the child grid has loaded.  Am I missing some point on how I should achive this?
0
Yavor Georgiev
Telerik team
answered on 09 Jun 2010, 04:19 PM
Hello Monte Baker,

 ChildrenOfType<>().Where() returns a collection. You need to call FirstOrDefault() on it to get the first (because here you can get only one result) item. So your complete check is something like:

var childGrid = row.ChildrenOfType<RadGridView>().Where(c => c.Name == "MyChild").FirstOrDefault();
if (childGrid != null)
{
   // do something with childGrid
}        

Sincerely yours,
Yavor Georgiev
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
Monte Baker
Top achievements
Rank 2
Answers by
Yavor Georgiev
Telerik team
Monte Baker
Top achievements
Rank 2
Share this question
or