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

GridView Data Binding Issue?

5 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 01 Apr 2010, 05:13 PM
In my Silverlight application I have a RadCalendar and a RadGridView.  As the user selects new dates in the RadCalendar, new data is requested asynchronously from the ADO.Net dataservice.

The RadGridView is also displaying a RowDetailView when an row is selected.  In the RowDetailView, I want the user to be able to edit a couple of the fields and have those changes reflected back in the main view of the RadGridView.  However, any changes made in the RowDetailView are not reflected in the RadGridView.  If you changing to another row and then back to the row that the changes were made on, the RowDetailView still has the "changed" data.

My question is how do I get those changes to show up in the main RadGridView after making changes in the RowDetailView?

Here is my RadGridView definition:
                                <telerikGridView:RadGridView x:Name="routeStop"  
                                                             IsReadOnly="False" AutoGenerateColumns="False" ShowGroupPanel="False" EnableColumnVirtualization="False" 
                                                             SelectionChanged="routeStop_SelectionChanged" 
                                                             RowDetailsVisibilityMode="VisibleWhenSelected" RowDetailsTemplate="{StaticResource RouteStopInfoDetailsTemplate}" AreRowDetailsFrozen="True" RenderTransformOrigin="0.5,0.5" > 
 
 
                                    <telerikGridView:RadGridView.Columns> 
                                        <telerikGridView:GridViewDataColumn Header="Stop" UniqueName="Stop"
 
                                        </telerikGridView:GridViewDataColumn> 
                                        <telerikGridView:GridViewDataColumn Header="Master BOL" UniqueName="MasterBOL"
 
                                        </telerikGridView:GridViewDataColumn> 
                                        <telerikGridView:GridViewDataColumn Header="Supplier Code" UniqueName="SupplierCode" > 
 
                                        </telerikGridView:GridViewDataColumn> 
                                        <telerikGridView:GridViewDataColumn Header="ShipFrom" UniqueName="ShipFrom"
 
                                        </telerikGridView:GridViewDataColumn> 
                                        <telerikGridView:GridViewDataColumn Header="Trailer" UniqueName="TrailerNumber"
 
                                        </telerikGridView:GridViewDataColumn> 
                                        <telerikGridView:GridViewDataColumn Header="SCAC" UniqueName="TrailerScac"
 
                                        </telerikGridView:GridViewDataColumn> 
                                    </telerikGridView:RadGridView.Columns> 
 
                                </telerikGridView:RadGridView> 
 

Here is my code to request the data from the ADO.Net Dataservice:
        private void UpdateRouteStopView() 
        { 
            routeStop.IsBusy = true
 
            DateTime selectedDateTime = calendarControl.SelectedDate.Value; 
 
            var query = (from asnInMaster in dbContext.AsnInMaster 
                         where asnInMaster.ETA >= selectedDateTime && asnInMaster.ETA <= selectedDateTime.AddDays(1.0) && asnInMaster.Route == selectedRoute 
                         orderby asnInMaster.Stop 
                         select asnInMaster); 
 
            var dsQuery = (DataServiceQuery<AsnInMaster>)query; 
            dsQuery.BeginExecute(RouteStopCallback, dsQuery); 
        } 
 
 
        private void RouteStopCallback(IAsyncResult asyncResult) 
        { 
            try 
            { 
                DataServiceQuery<AsnInMaster> query = asyncResult.AsyncState as DataServiceQuery<AsnInMaster>
                routeStop.ItemsSource = query.EndExecute(asyncResult).ToList(); 
 
            } 
            catch 
            { 
            } 
            finally 
            { 
                routeStop.IsBusy = false
            } 
        } 
 

And here is the definition of my RowDetailView:
        <Grid x:Name="detailsGrid" Height="300"
            <Grid.RowDefinitions> 
                <RowDefinition Height="30"/> 
                <RowDefinition Height="20"/> 
                <RowDefinition Height="20"/> 
                <RowDefinition Height="20"/> 
                <RowDefinition Height="20"/> 
                <RowDefinition Height="20"/> 
            </Grid.RowDefinitions> 
            <Grid.ColumnDefinitions> 
                <ColumnDefinition Width="Auto" /> 
                <ColumnDefinition Width="Auto" /> 
                <ColumnDefinition Width="30" /> 
                <ColumnDefinition Width="Auto" /> 
                <ColumnDefinition Width="Auto" /> 
                <ColumnDefinition Width="30" /> 
                <ColumnDefinition Width="30" /> 
            </Grid.ColumnDefinitions> 
            <TextBlock Text="Route Stop Details Information" FontWeight="Bold" FontFamily="Comic Sans MS" FontSize="18" 
                                Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"/> 
            <!-- Column 0 & 1 Definitions --> 
            <TextBlock Text="ASN MasterID: " Margin="0,0,0,0" FontWeight="Bold" 
                                Grid.Row="1" Grid.Column="0" /> 
            <TextBox Text="{Binding AsnInMasterID}" Margin="0,0,0,0" Grid.Row="1" 
                                Grid.Column="1"/> 
            <TextBlock Text="Master BOL: " Margin="0,0,0,0" FontWeight="Bold" 
                                Grid.Row="2" Grid.Column="0" /> 
            <TextBox x:Name="masterBOL" Text="{Binding MasterBOL, Mode=TwoWay}" Margin="0,0,0,0" Grid.Row="2" 
                                Grid.Column="1" /> 
            <TextBlock Text="Supplier Code: " Margin="0,0,0,0" FontWeight="Bold" 
                                Grid.Row="3" Grid.Column="0" /> 
            <TextBox Text="{Binding SupplierCode, Mode=TwoWay}" Margin="0,0,0,0" Grid.Row="3" 
                                Grid.Column="1" /> 
            <TextBlock Text="ShipFrom: " Margin="0,0,0,0" FontWeight="Bold" 
                                Grid.Row="4" Grid.Column="0" /> 
            <TextBox Text="{Binding ShipFrom}" Margin="0,0,0,0" Grid.Row="4" 
                                Grid.Column="1" /> 
 
            <!-- Column 3 & 4 Definitions --> 
            <TextBlock Text="Trailer #: " Margin="0,0,0,0" FontWeight="Bold" 
                                Grid.Row="1" Grid.Column="3" /> 
            <TextBlock Text="{Binding TrailerNumber}" Margin="0,0,0,0" Grid.Row="1" 
                                Grid.Column="4"/> 
            <TextBlock Text="SCAC: " Margin="0,0,0,0" FontWeight="Bold" 
                                Grid.Row="2" Grid.Column="3" /> 
            <TextBlock x:Name="SCAC" Text="{Binding TrailerScac}" Margin="0,0,0,0" Grid.Row="2" 
                                Grid.Column="4" /> 
        </Grid> 
 


Any help would be greatly appreciated.

5 Answers, 1 is accepted

Sort by
0
Lee
Top achievements
Rank 1
answered on 01 Apr 2010, 07:21 PM
Update:
Well it looks like the updated data is "binding" to the changes but the grid is not automatically updating to reflect the changes.  If I Rebind() the RadGridView the data does show up.

Now the problem is that I'm not sure how to tell the RadGridView to Rebind() from the RowDetailView template.  I don't see any way to access the grid from the RowDetailView template codebehind.

Is there a way for me to force the Rebind() from the RowDetailView template once the user changes the data?

Thanks.
0
Rossen Hristov
Telerik team
answered on 06 Apr 2010, 08:42 AM
Hello Lee Weisenberger,

You can encapsulate your row details control, i.e. "detailsGrid" in a new UserControl. Then you can obtain a reference to the parent grid from the code-behind of this control by using the ParentOfType<T>() method. This extension method is in the Telerik.Windows.Controls namespace.

//...
var parentGrid = this.ParentOfType<RadGridView>();
//...

Let me know if there are problems.

Sincerely yours,
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
Lee
Top achievements
Rank 1
answered on 06 Apr 2010, 12:32 PM
Ross, thanks for your response, but I'm not sure what you mean?

My detailsGrid is already encapsulated inside of it's own UserControl, but I'm not clear what you are suggesting with the code snippet you supplied.  

What am I supposed to do once I have a reference to the parent control of the main grid from within the detailsGrid?
0
Accepted
Rossen Hristov
Telerik team
answered on 06 Apr 2010, 01:06 PM
Hello Lee Weisenberger,

You said that you want to rebind the parent grid, but you don't know how to get a reference to it from within the row details. I have explained how to obtain a reference to the parent grid. Now, since you have the reference to the parent grid, you can call its Rebind method.

Am I missing something?

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
Lee
Top achievements
Rank 1
answered on 06 Apr 2010, 01:42 PM
Sorry.  I've been dealing with several databinding issues since I submitted this question and your solution was not making sense when I read it.

That said, this resolved this issue.

Thank you.
Tags
GridView
Asked by
Lee
Top achievements
Rank 1
Answers by
Lee
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or