I am new to Telerik RadGridView and facing issues when using Telerik RadGridView with HierarchyChildTemplate.Here is the scenario I am trying to achieve -
1. I have a RadGridView with only 4 columns
2. In the same RadGridView I have HierarchyChildTemplate
3. Within HierarchyChildTemplate I have DataTemplate with RadTabControls and 4 RadTabItems
4. Every RadTabItem has TextBlocks,TextBoxes and ComboBoxes.
5. I have added the RadGridView table definitions and childdefinitions,so I get data populated in the radgrid rows and all controls
in the RadTabItems gets automatically populated.
6. I have also added the Edit Save and Cancel buttons outside the HierarchyChildTemplate to have a common functionality applied to all RadTab items.
The issue is that
- I am not able to get the values from the controls that I have placed in RadTabItems although all the controls have values.
- I am also not able to get the CurrentItem of the RadGridView.It always gives me first item of the RadGridView even if I am in
other Row.
I need help on this.
Many Thanks
Anurag
8 Answers, 1 is accepted
Depending on your particular settings, you may get the values displayed in the DataTemplate by the corresponding item of the grid. Furthermore, in case you find it more appropriate, you may achieve the same behavior by using the RowDetailsTemplate instead.
As far as your second requirement is concerned, you may try to set the IsSynchronizedWithCurrentItem property of the grid to "True".
Maya
the Telerik team
Based on your suggestion I am implementing the scenario. Now I have a requirement to load the Row as soon as the userclicks
the row, a kind of load on demand.Please can you share some example to achieve this.
<
Grid x:Name="LayoutRoot">
<telerikGridView:RadGridView x:Name="gridViewEmployeeList" GridLinesVisibility="Horizontal"
AutoGenerateColumns="False" IsBusy="False" IsReadOnly="True" RowIndicatorVisibility="Collapsed" RowDetailsVisibilityMode="VisibleWhenSelected">
<telerikGridView:RadGridView.Columns>
<telerikGridView:GridViewDataColumn Header="Emp Number" DataMemberBinding="{Binding EmpNumber}" HeaderTextAlignment="Center" Width="Auto" />
<telerikGridView:GridViewDataColumn Header="Emp Name" DataMemberBinding="{Binding Name}" HeaderTextAlignment="Center" Width="Auto" />
<telerikGridView:GridViewDataColumn Header="Location" DataMemberBinding="{Binding Location}" HeaderTextAlignment="Center" Width="Auto" />
<telerikGridView:GridViewDataColumn Header="Contact No" DataMemberBinding="{Binding MobileNumber}" TextWrapping="Wrap" HeaderTextAlignment="Center" Width="Auto"/>
<telerikGridView:GridViewDataColumn Header="Photo" DataMemberBinding="{Binding Photo.Byte}" TextWrapping="Wrap" HeaderTextAlignment="Center" Width="Auto"/>
<telerikGridView:GridViewDataColumn IsVisible="False" Header="Emp ID" DataMemberBinding="{Binding Empid}" TextWrapping="Wrap" HeaderTextAlignment="Center" Width="Auto"/>
</telerikGridView:RadGridView.Columns>
<telerikGridView:RadGridView.RowDetailsTemplate>
<DataTemplate>
<telerikNavigation:RadTabControl.....
<telerikNavigation:RadTabItem ....
<telerikNavigation:RadTabItem ....
</DataTemplate>
</telerikGridView:RadGridView.RowDetailsTemplate>
</telerikGridView:RadGridView>
</Grid>
Many Thanks
Anurag
Generally, the RowDetails will be loaded on demand once the user clicks on the corresponding item. However, in case you need to implement some additional logic, you may use either LoadingRowDetails or RowDetailsVisibilityChanged events.You may take a look at our online documentation for further reference.
Maya
the Telerik team
Thanks.
I have managed it.Now I am using RowDetailsTemplate and used SelectionChanged event of the grid and hooked
this event. In the SelectionChanged event handler of the RadGridView I am using SelectedItem property to get the selected
Row and applied Custom Logic of Edit/Save/Cancel on it.
Many Thanks
Anurag
Hi We are using Telerik version 2010.2.0924.35 in one of our WPF application.
We are using HierarchyChildTemplate which binds data from backend. Which is not refreshing for the first time. Here are details steps
1. HierarchyChildTemplate refreshes when user clicks on + (Expand button) for the first time
2. Data is being retrieved from DB but its not binding to the HierarchyChildTemplate RadGridView
3. When we close the expand and try to reopen again we are seeing the data. this issue is happening for the first time expand only.
Sample Xaml code
<telerik:RadGridView.HierarchyChildTemplate>
<DataTemplate>
<telerik:RadGridView Height="Auto" Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Top"
AutoGenerateColumns="False" ItemsSource="{Binding ExceptionOverride, Mode=TwoWay}"
ShowGroupPanel="False" SelectionUnit="Cell"
ClipboardCopyMode="Default" SelectionMode="Extended" CanUserSortColumns="True" >
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=HsdAppNumber.DisplayValue}" Header="Contract" UniqueName="Contract" IsReadOnly="True" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=State.DisplayValue}" Header="State" UniqueName="State" IsReadOnly="True" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=County.DisplayValue}" Header="County" UniqueName="County" IsReadOnly="True" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=SpecialtyDescription.DisplayValue}" Header="HSD Specialty" UniqueName="SpecialtyName" IsReadOnly="True" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Reason.DisplayValue}" Header="Reason For Override" UniqueName="Reason" IsReadOnly="True" />
<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding Path=FlgEligible.DisplayValue}" UniqueName="ExceptionOverride" Header="Delete" EditTriggers="CellClick" AutoSelectOnEdit="True">
<telerik:GridViewCheckBoxColumn.CellStyle>
<Style TargetType="telerik:GridViewCell"></Style>
</telerik:GridViewCheckBoxColumn.CellStyle>
</telerik:GridViewCheckBoxColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>
Code Behind for RowIsExpandedChanged event
var childGridViewList = row.ChildrenOfType<RadGridView>();
if (!childGridViewList.IsNullOrEmpty() && null != childGridViewList.FirstOrDefault())
{
var childExceptionOverrideGridview = childGridViewList.FirstOrDefault();
var exceptionOverride = this.viewModel.GetExceptionOverride(availableProviderDataItem.Id.Current);
//Clearing the ItemSource of child grid, re-assigning the ItemSource and Rebind the grid to fix UI refresh issue #335100
childExceptionOverrideGridview.ItemsSource = null;
childExceptionOverrideGridview.ItemsSource = exceptionOverride;
availableProviderDataItem.ExceptionOverride = exceptionOverride;
childExceptionOverrideGridview.Rebind();
}
Though I cannot confirm the exact cause for this behavior, my best guess is that it is due to a timing issue. so, instead of using the RowIsExpandedChanged event, may I ask you to try using the RowIsExpandedChanging one? It is raised when the row is about to be expanded, whereas the first one is raised when the row is already expanded. Does this solve the issue you are experiencing? If this does not help, can you please try updating your assemblies to the newest possible version? Is the problem reproduced with the newer version as well?
Regards,
Stefan
Progress Telerik
Thanks for the update.
After the additional investigation I made, it seems that this might turn to be a timing issue. My best guess is that it is due to the hierarchical RadGridView being accessed directly through the VisualTree. Note, that such an approach is generally not recommended when using RadGridView. As previously mentioned in this thread, you can try using the RowDetails mechanism instead. Through it you should be able to achieve such on-demand loading of the hierarchical data through the events provided by the control. You may find the Find a Control in RowDetailsTemplate topic useful for achieving your goal.
Hope this helps.
Regards,
Stefan
Progress Telerik