Browse Source

Added function to Update a set of rows with a set of items.

Kenric Nugteren 7 months ago
parent
commit
56dc39a69c
1 changed files with 15 additions and 2 deletions
  1. 15 2
      inabox.wpf/DynamicGrid/DynamicGrid.cs

+ 15 - 2
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -1245,6 +1245,20 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
         ObjectToRow(obj, _recordmap[row]);
     }
 
+    /// <summary>
+    /// Update/sync the data in <paramref name="rows"/> with that of <paramref name="objs"/>.
+    /// </summary>
+    public void UpdateRows(CoreRow[] rows, T[] objs, bool invalidateRows = true)
+    {
+        for(var i = 0; i < objs.Length; ++i)
+        {
+            UpdateRow(rows[i], objs[i]);
+            if (invalidateRows)
+            {
+                InvalidateRow(rows[i]);
+            }
+        }
+    }
 
     public void AddRow(CoreRow row)
     {
@@ -1834,8 +1848,7 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
             if (EditItems(items))
             {
                 var sel = SelectedRows;
-                for (var i = 0; i < items.Length; i++)
-                    UpdateRow(rows[i], items[i]);
+                UpdateRows(rows, items, invalidateRows: false);
                 InvalidateGrid();
                 SelectedRows = sel;
                 DoChanged();