Skip to content

Commit 235dae2

Browse files
ES-999593 - Resolved the ReadMe file changes in the sample repository
1 parent cdce8bb commit 235dae2

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# How to programmatically scroll and select the records of the multi-level DetailsView on initial loading in UWP DataGrid (SfDataGrid)?
1+
# How to Programmatically Scroll and Select the Records of the Multi-level DetailsView on Initial Loading in UWP DataGrid?
22

3-
## About the sample
3+
This sample illustrates how to programmatically scroll and select the records of the multi-level DetailsView on initial loading in [UWP DataGrid](https://www.syncfusion.com/uwp-ui-controls/datagrid) (SfDataGrid).
44

5-
This sample illustrates how to programmatically scroll and select the records of the multi-level DetailsView on initial loading in UWP DataGrid.
5+
You can select the records of the Master-DetailsView programmatically on initial loading by setting the corresponding child grid row index to the [SfDataGrid.SelectedIndex](https://help.syncfusion.com/cr/uwp/Syncfusion.UI.Xaml.Grid.SfGridBase.html#Syncfusion_UI_Xaml_Grid_SfGridBase_SelectedIndex) property. This can be achieved by passing the row index of both the parent and child grids. Before setting the SelectedIndex to childgrid, you need to check whether the corresponding parent record is in the expanded or collapsed state. When it is expanded, you can directly select the records of the child grid; otherwise, you need to expand it manually by using the [SfDataGrid.ExpandDetailsViewAt](https://help.syncfusion.com/cr/uwp/Syncfusion.UI.Xaml.Grid.SfDataGrid.html#Syncfusion_UI_Xaml_Grid_SfDataGrid_ExpandDetailsViewAt_System_Int32_) helper method. You can also bring the corresponding DetailsView grid into the view by using the [DetailsViewManager.BringToView](https://help.syncfusion.com/cr/uwp/Syncfusion.UI.Xaml.Grid.DetailsViewManager.html#Syncfusion_UI_Xaml_Grid_DetailsViewManager_BringIntoView_System_Int32_) helper method. This is demonstrated in the following code example.
66

7-
You can select the records of the Master-DetailsView programmatically on initial loading by setting the corresponding child grid row index to the SfDataGrid.SelectedIndex property. This can be achieved by passing the row index of both the parent and child grids. Before setting the SelectedIndex to childgrid, you need to check whether the corresponding parent record is in the expanded or collapsed state. When it is expanded, you can directly select the records of the child grid; otherwise, you need to expand it manually by using the SfDataGrid.ExpandDetailsViewAt helper method. You can also bring the corresponding DetailsView grid into the view by using the DetailsViewManager.BringToView helper method. This is demonstrated in the following code example.
8-
9-
10-
```Xaml
7+
#### XAML
8+
``` xml
119
<syncfusion:SfDataGrid x:Name="dataGrid"
1210
ColumnSizer="Auto"
1311
AutoGenerateColumns="True"
@@ -17,6 +15,7 @@ You can select the records of the Master-DetailsView programmatically on initial
1715
AutoGeneratingRelations="On_DataGrid_AutoGeneratingRelations">
1816
```
1917

18+
#### C#
2019
```c#
2120

2221
private void On_DataGrid_AutoGeneratingRelations(object sender, AutoGeneratingRelationsArgs e)
@@ -35,12 +34,8 @@ private void DoSelection()
3534

3635
if (empToSelect != null)
3736
{
38-
3937
this.dataGrid.SelectedItem = empToSelect;
40-
4138
var employeeRowIndex = this.dataGrid.ResolveToRowIndex(this.dataGrid.SelectedIndex);
42-
43-
4439
this.ExpandAndSelectDetailsView(this.dataGrid, employeeRowIndex, 22, "Orders");
4540

4641
dataGrid.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
@@ -49,12 +44,8 @@ private void DoSelection()
4944

5045
if (orderGrid != null)
5146
{
52-
5347
var ordersRowindex = orderGrid.ResolveToRowIndex(orderGrid.SelectedIndex);
54-
5548
this.ExpandAndSelectDetailsView(orderGrid, ordersRowindex, 2, "Sales");
56-
57-
5849
dataGrid.SelectionController.GetType().GetMethod("ScrollToRowIndex", System.Reflection.BindingFlags.Instance
5950
| System.Reflection.BindingFlags.NonPublic).Invoke(dataGrid.SelectionController, new object[] { dataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex });
6051
}
@@ -66,8 +57,10 @@ private void ExpandAndSelectDetailsView(SfDataGrid dataGrid, int parentRowIndex,
6657
{
6758
//Checks whether the given index is parent row index or not.
6859
bool IsDetailsViewIndex = dataGrid.IsInDetailsViewIndex(parentRowIndex);
60+
6961
if (IsDetailsViewIndex == true)
7062
return;
63+
7164
//Gets the record of the parent row index.
7265
var record = dataGrid.View.Records[dataGrid.ResolveToRecordIndex(parentRowIndex)];
7366
//Gets the DetailsViewManager by using Reflection.
@@ -77,14 +70,17 @@ private void ExpandAndSelectDetailsView(SfDataGrid dataGrid, int parentRowIndex,
7770
var childSource = detailsViewManager.GetChildSource(record.Data, relationalColumn);
7871
var GetChildSourceCount = detailsViewManager.GetType().GetMethod("GetChildSourceCount", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
7972
var ChildSourceCount = GetChildSourceCount.Invoke(detailsViewManager, new object[] { childSource });
73+
8074
if ((int)ChildSourceCount == 0)
8175
return;
8276

8377
//Checks whether the record is Expanded or Collapsed.
8478
//When it is in the collapsed state, you need to expand the particular DetailsView based on the index.
85-
if (!record.IsExpanded) dataGrid.ExpandDetailsViewAt(dataGrid.ResolveToRecordIndex(parentRowIndex));
79+
if (!record.IsExpanded)
80+
dataGrid.ExpandDetailsViewAt(dataGrid.ResolveToRecordIndex(parentRowIndex));
8681
//Gets the index of the DetailsView.
8782
int index = 0;
83+
8884
foreach (var def in dataGrid.DetailsViewDefinition)
8985
{
9086
if (def.RelationalColumn == relationalColumn)
@@ -93,6 +89,7 @@ private void ExpandAndSelectDetailsView(SfDataGrid dataGrid, int parentRowIndex,
9389
index = parentRowIndex + index + 1;
9490
}
9591
}
92+
9693
//Brings the parent row in the view.
9794
var rowcolumnIndex = new RowColumnIndex(index, 1);
9895
dataGrid.ScrollInView(rowcolumnIndex);
@@ -102,6 +99,7 @@ private void ExpandAndSelectDetailsView(SfDataGrid dataGrid, int parentRowIndex,
10299
//When the specified index is not currently in view, you can bring that row in to the view by using the SfDataGrid.ScrollInView method.
103100
var firstline = dataGrid.GetVisualContainer().ScrollRows.GetVisibleLines().FirstOrDefault(line => line.Region == ScrollAxisRegion.Body);
104101
var lastline = dataGrid.GetVisualContainer().ScrollRows.GetVisibleLines().LastOrDefault(line => line.Region == ScrollAxisRegion.Body);
102+
105103
if (firstline.LineIndex >= index || lastline.LineIndex <= index)
106104
{
107105
//Brings the details view grid in to the view and sets the child grid's SelectedIndex as the ChildRowIndex.
@@ -122,5 +120,4 @@ private void ExpandAndSelectDetailsView(SfDataGrid dataGrid, int parentRowIndex,
122120
```
123121

124122
## Requirements to run the demo
125-
Visual Studio 2015 and above versions
126-
123+
Visual Studio 2015 and above versions

0 commit comments

Comments
 (0)