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

Access to nested GridView

4 Answers 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ilusha
Top achievements
Rank 1
ilusha asked on 27 Mar 2014, 06:06 AM
Hello!
I have Self-referenced hierachical GridView sach as:

<telerik:RadGridView RowIsExpandedChanged="RadGridView1_OnRowIsExpandedChanged" DataLoadMode="Asynchronous" AutoGenerateColumns="False" DataLoading="RadGridView1_OnDataLoading" GroupRenderMode="Flat"  ItemsSource="{Binding Path=., Mode=TwoWay}" x:Name="RadGridView1" ShowGroupPanel="False" Grid.Row="3" Grid.ColumnSpan="2">
            <telerik:RadGridView.Resources>
                <DataTemplate x:Key="CellTemplateForColorOfLinesEdit">
                    <telerik:RadColorPicker SelectedColorChanged="OnSelectedColorChanged" SelectedColor="{Binding StoreLayouts[0].ColorForLines.Color, Mode=TwoWay}"></telerik:RadColorPicker>
                </DataTemplate>
                <DataTemplate x:Key="CellTemplateForColorOfLines">
                    <Border Background="{Binding StoreLayouts[0].ColorForLines}">
                        <TextBlock></TextBlock>
                    </Border>
                </DataTemplate>
                <DataTemplate x:Key="CellTemplateForX">
                    <telerik:RadNumericUpDown ValueChanged="OnXValueChanged"  Value="{Binding StoreLayouts[0].X, Mode=TwoWay}" CustomUnit="м." NumberDecimalDigits="2" ValueFormat="Numeric" SmallChange="0.01"/>
                </DataTemplate>
                <DataTemplate x:Key="CellTemplateForY">
                    <telerik:RadNumericUpDown ValueChanged="OnYValueChanged" Value="{Binding StoreLayouts[0].Y, Mode=TwoWay}" CustomUnit="м." NumberDecimalDigits="2" ValueFormat="Numeric" SmallChange="0.01"/>
                </DataTemplate>
                <DataTemplate x:Key="CellTemplateForWidth">
                    <telerik:RadNumericUpDown ValueChanged="OnWidthChanged" Value="{Binding StoreLayouts[0].Width, Mode=TwoWay}" CustomUnit="м." NumberDecimalDigits="2" ValueFormat="Numeric" SmallChange="0.01"/>
                </DataTemplate>
                <DataTemplate x:Key="CellTemplateForHeight">
                    <telerik:RadNumericUpDown ValueChanged="OnHeightChanged" Value="{Binding StoreLayouts[0].Height, Mode=TwoWay}" CustomUnit="м." NumberDecimalDigits="2" ValueFormat="Numeric" SmallChange="0.01"/>
                </DataTemplate>
                <DataTemplate x:Key="CellTemplateForGWidth">
                    <telerik:RadNumericUpDown ValueChanged="OnGridWidthChanged" Value="{Binding StoreLayouts[0].Grid_width, Mode=TwoWay}" CustomUnit="м." NumberDecimalDigits="2" ValueFormat="Numeric" SmallChange="0.01"/>
                </DataTemplate>
                <DataTemplate x:Key="CellTemplateForGHeight">
                    <telerik:RadNumericUpDown ValueChanged="OnGridHeightChanged" Value="{Binding StoreLayouts[0].Grid_height, Mode=TwoWay}" CustomUnit="м." NumberDecimalDigits="2" ValueFormat="Numeric" SmallChange="0.01"/>
                </DataTemplate>
            </telerik:RadGridView.Resources>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Наименование" DataMemberBinding="{Binding Storename}"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Цвет линий" CellTemplate="{StaticResource CellTemplateForColorOfLines}" CellEditTemplate="{StaticResource CellTemplateForColorOfLinesEdit}" ></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Шаг сетки по ширине" CellTemplate="{StaticResource CellTemplateForGWidth}"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Шаг сетки по высоте" CellTemplate="{StaticResource CellTemplateForGHeight}"></telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.FilterDescriptors>
                <telerik:FilterDescriptor Member="Storeparentid" Operator="IsEqualTo" Value="null"></telerik:FilterDescriptor>
            </telerik:RadGridView.FilterDescriptors>
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition>
                    <telerik:GridViewTableDefinition.Relation>
                        <telerik:TableRelation IsSelfReference="True">
                            <telerik:TableRelation.FieldNames>
                                <telerik:FieldDescriptorNamePair
                            ParentFieldDescriptorName="Storeid"
                            ChildFieldDescriptorName="Storeparentid" />
                            </telerik:TableRelation.FieldNames>
                        </telerik:TableRelation>
                    </telerik:GridViewTableDefinition.Relation>
                </telerik:GridViewTableDefinition>
            </telerik:RadGridView.ChildTableDefinitions>
        </telerik:RadGridView>


With my data there are 5 level of nested grid. I have another tree view with this hierarchy. My goal is to synchronize opened element between this 2 control. But my nested GridView filled in code behid sach as:

 var datacontrol = (RadGridView)sender;
            if (datacontrol.ParentRow == null) return;
            datacontrol.ShowGroupPanel = false;
            datacontrol.AutoGenerateColumns = false;
            datacontrol.DataLoadMode = DataLoadMode.Asynchronous;
            var storeNameColumn = new GridViewDataColumn { DataMemberBinding = new Binding("Storename"), Header = "Наименование" };
            datacontrol.Columns.Add(storeNameColumn);
            var storeTypeName = new GridViewDataColumn { DataMemberBinding = new Binding("StoreType.StoreTypeName"), Header = "Тип" };
            datacontrol.Columns.Add(storeTypeName);
            var storeNumber = new GridViewDataColumn { DataMemberBinding = new Binding("Storenumber"), Header = "Номер" };
            datacontrol.Columns.Add(storeNumber);
            var xColumn = new GridViewDataColumn { Header = "X", CellTemplate = RadGridView1.Resources["CellTemplateForX"] as DataTemplate, UniqueName = "XCOL" };
            datacontrol.Columns.Add(xColumn);
            var yColumn = new GridViewDataColumn { Header = "Y", CellTemplate = RadGridView1.Resources["CellTemplateForY"] as DataTemplate };
            datacontrol.Columns.Add(yColumn);
            var widthColumn = new GridViewDataColumn { Header = "Ширина", CellTemplate = RadGridView1.Resources["CellTemplateForWidth"] as DataTemplate };
            datacontrol.Columns.Add(widthColumn);
            var heightColumn = new GridViewDataColumn { Header = "Высота", CellTemplate = RadGridView1.Resources["CellTemplateForHeight"] as DataTemplate };
            datacontrol.Columns.Add(heightColumn);
            var colorPickerColumn = new GridViewDataColumn
            {
                DataMemberBinding = new Binding("ColorForLines"),
                Header = "Цвет линий",
                CellTemplate = RadGridView1.Resources["CellTemplateForColorOfLines"] as DataTemplate,
                CellEditTemplate = RadGridView1.Resources["CellTemplateForColorOfLinesEdit"] as DataTemplate
            };
            datacontrol.Columns.Add(colorPickerColumn);
            var gridWidthColumn = new GridViewDataColumn { CellTemplate = RadGridView1.Resources["CellTemplateForGWidth"] as DataTemplate, Header = "Шаг сетки по ширине" };
            datacontrol.Columns.Add(gridWidthColumn);
            var gridHeightColumn = new GridViewDataColumn { CellTemplate = RadGridView1.Resources["CellTemplateForGHeight"] as DataTemplate, Header = "Шаг сетки по высоте" };
            datacontrol.Columns.Add(gridHeightColumn);

As I understand the event  DataLoading="RadGridView1_OnDataLoading" occures when row is expanded. Before that moment I can't find element in nested grid. My querstion is:
1)How to force DataLoading event for all nested grid (I want for the grid will be loaded immediately and full without rise DataLoading event)
2)How to find element in nested grid (may be on 3 or 4 level)
3)Is it possible to expand element in nested grid and recursevly expand all his parent row.
Sorry for my English. 



4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 27 Mar 2014, 10:07 AM
Hi,

RadGridView's hierarchy will be only created on demand. This means that a child/hierarchy grid will not be available until it is visualized. Consequently, you will get its value as null if you are trying to get it before the hierarchical item is opened. 

Please note that you can only get a reference of the details GridView that has already been loaded (i.e. you have expanded the hierarchy).
To achieve this, you can try initially expanding all the hierarchy:

RadGridView1.ExpandAllHierarchyItems();
 
As a side note I should point out that setting DataLoadMode="Asyncronous" is generally not recommended as it could lead to some problems. This is an old mode and it is not relevant with our latest version. Please remove it.

Regards,
Didie
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
ilusha
Top achievements
Rank 1
answered on 27 Mar 2014, 10:23 AM
Thanks for your reply!
I've too thought about RadGridView1.ExpandAllHierarchyItems(). It is works with 1 level hierarchy. But What about next levels. Is it possible to know when row expand visualisation is complete? 
Simply my question is is it possible to open all nested grid view frm 3 or 4 level hierarchy with RadGridView1.ExpandAllHierarchyItems()?
Thanks!
0
Accepted
Dimitrina
Telerik team
answered on 27 Mar 2014, 11:37 AM
Hi,

To expand all the hierarchies I would suggest you to subscribe to the Loaded or DataLoaded events of the child GridViews. This way you may get references to them in the code behind and call the ExpandAllHierarchyItems method for them as well. 

Regards,
Didie
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
ilusha
Top achievements
Rank 1
answered on 27 Mar 2014, 12:07 PM
It is ingeniously!!!! Great thanks!!!
Tags
GridView
Asked by
ilusha
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
ilusha
Top achievements
Rank 1
Share this question
or