Update the child row data in the GridDataBoundGrid while updating the DataSource.
The value is updated to the WinForms GridDataBoundGrid (flat grid) when it is changed or when the records are updated in the DataSource, by default. But, in the nested table or child row, you need to update the child row records based on its value by refreshing the row range. To refresh the row range, the ListChanged event can be used. In this event, the row can be refreshed by using the RefreshRange method when the items are changed.
C#
private void list_ListChanged(object sender, ListChangedEventArgs e) { IBindingList list = (IBindingList)sender; if (list != null) { //Finds the parent row... int parentRow = findParentRowFromChildList(list); if (parentRow == -1) { // Checks parent row for change. if (e.ListChangedType == ListChangedType.ItemChanged) { UpdateThisParentRow(e.NewIndex); } return; } int screenRow = parentRow + e.NewIndex + 1; for (int j = 1; j <= e.NewIndex; ++j) screenRow += ScreenRowsInChildren(parentRow + j); Console.WriteLine("Item#=" + e.NewIndex.ToString() + " parentRow: " + parentRow.ToString() + " screenRow: " + screenRow.ToString()); switch (e.ListChangedType) { case ListChangedType.ItemChanged: //Redraws screen row to show the change. this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Row(screenRow)); Console.WriteLine("ItemChanged"); break; case ListChangedType.ItemAdded: //Opens and closes the parent node. RefreshRow(parentRow); //Puts the currentcell somewhere. this.gridDataBoundGrid1.Focus(); this.gridDataBoundGrid1.CurrentCell.Activate(screenRow - 1, 2); //minus 1 because of new row. Console.WriteLine("ItemAdded"); break; case ListChangedType.ItemDeleted: //Opens and closes the parent node. RefreshRow(parentRow); //Puts the currentcell somewhere. this.gridDataBoundGrid1.Focus(); this.gridDataBoundGrid1.CurrentCell.Activate(screenRow, 2); //minus 1 because of the new row. Console.WriteLine("ItemDeleted"); break; default: break; } } }
VB
Private Sub list_ListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs) Dim list As IBindingList = CType(sender, IBindingList) If list IsNot Nothing Then 'Finds the parent row... Dim parentRow As Integer = findParentRowFromChildList(list) If parentRow = -1 Then 'Checks parent row for change. If e.ListChangedType = ListChangedType.ItemChanged Then UpdateThisParentRow(e.NewIndex) End If Return End If Dim screenRow As Integer = parentRow + e.NewIndex + 1 For j As Integer = 1 To e.NewIndex screenRow += ScreenRowsInChildren(parentRow + j) Next j Console.WriteLine("Item#=" & e.NewIndex.ToString() & " parentRow: " & parentRow.ToString() & " screenRow: " & screenRow.ToString()) Select Case e.ListChangedType Case ListChangedType.ItemChanged 'Redraws screen row to show the change. Me.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Row(screenRow)) Console.WriteLine("ItemChanged") Case ListChangedType.ItemAdded 'Opens and closes the parent node. RefreshRow(parentRow) 'Puts the currentcell somewhere. Me.gridDataBoundGrid1.Focus() Me.gridDataBoundGrid1.CurrentCell.Activate(screenRow - 1, 2) 'minus 1 because of the new row. Console.WriteLine("ItemAdded") Case ListChangedType.ItemDeleted 'Opens and closes the parent node. RefreshRow(parentRow) 'Puts the currentcell somewhere. Me.gridDataBoundGrid1.Focus() Me.gridDataBoundGrid1.CurrentCell.Activate(screenRow, 2) 'minus 1 because of new row Console.WriteLine("ItemDeleted") Case Else End Select End If End Sub
The following screenshot represents the Grid before updating:
The following screenshot represents the Grid after updating:
Sample Links:
Conclusion
I hope you enjoyed learning about how to update the Child Row data in the GridDataBoundGrid while updating the DataSource.
You can refer to our WinForms GridDataBoundGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridDataBoundGrid documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!