Forráskód Böngészése

Fixed SelectedRecords issue when initialising grids

Frank van den Bos 2 éve
szülő
commit
819832d06e
1 módosított fájl, 48 hozzáadás és 52 törlés
  1. 48 52
      inabox.wpf/DynamicGrid/DynamicGrid.cs

+ 48 - 52
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -1167,7 +1167,8 @@ namespace InABox.DynamicGrid
 
         protected virtual void SelectItems(CoreRow[]? rows)
         {
-            OnSelectItem?.Invoke(this, new DynamicGridSelectionEventArgs(rows));
+            if (IsReady)
+                OnSelectItem?.Invoke(this, new DynamicGridSelectionEventArgs(rows));
 
             DuplicateBtn.Visibility =
                 typeof(T).IsAssignableTo(typeof(IDuplicatable)) && rows != null && rows.Length >= 1 ? Visibility.Visible : Visibility.Collapsed;
@@ -1975,68 +1976,63 @@ namespace InABox.DynamicGrid
             // I don't pretend to know why it works; this is probably the strangest problem I've ever come across.
             if(reloadcolumns)
                 DataGrid.ItemsSource = null;
+            
+            if (reloadcolumns) 
+                ReloadColumns();
 
-            //using (var d = Dispatcher.DisableProcessing())
+            if (reloaddata)
             {
-                if (reloadcolumns) 
-                    ReloadColumns();
-
-                if (reloaddata)
-                {
-                    _lookupcache.Clear();
+                _lookupcache.Clear();
 
-                    var criteria = new Filters<T>();
-                    var filter = DefineFilter();
-                    if (filter != null)
-                        criteria.Add(filter);
+                var criteria = new Filters<T>();
+                var filter = DefineFilter();
+                if (filter != null)
+                    criteria.Add(filter);
 
-                    var columns = DataColumns();
+                var columns = DataColumns();
 
-                    var sort = LookupFactory.DefineSort<T>();
-                    if (sort == null && IsSequenced)
-                        sort = new SortOrder<T>("Sequence");
+                var sort = LookupFactory.DefineSort<T>();
+                if (sort == null && IsSequenced)
+                    sort = new SortOrder<T>("Sequence");
 
-                    Reload(
-                        criteria
-                        , columns
-                        , ref sort
-                        , (table, exception) =>
+                Reload(
+                    criteria
+                    , columns
+                    , ref sort
+                    , (table, exception) =>
+                    {
+                        if (exception != null)
                         {
-                            if (exception != null)
+                            Dispatcher.Invoke(() =>
                             {
-                                Dispatcher.Invoke(() =>
-                                {
-                                    MessageBox.Show(String.Format("Error: {0}", exception.Message));
-                                });                                
-                            }
-                            else if(table is not null)
+                                MessageBox.Show(String.Format("Error: {0}", exception.Message));
+                            });                                
+                        }
+                        else if (table is not null)
+                        {
+                            MasterData = table;
+                            Dispatcher.Invoke(() =>
                             {
-                                MasterData = table;
-                                Dispatcher.Invoke(() =>
-                                {
-                                    ProcessData(reloadcolumns, reloaddata);
-                                    DoAfterRefresh();
-                                    bRefreshing = false;
-                                    IsReady = true;
-                                });
-                            }
+                                ProcessData(reloadcolumns, reloaddata);
+                                DoAfterRefresh();
+                                bRefreshing = false;
+                                IsReady = true;
+                            });
                         }
-                    );
-                }
-                else
-                {
-                    ProcessData(reloadcolumns, reloaddata);
-                    DoAfterRefresh();
-                    bRefreshing = false;
-                    IsReady = true;
-                    
-                    Loading.BeginAnimation(Label.OpacityProperty, null);
-                    Loading.Visibility = Visibility.Collapsed;
-                }
+                    }
+                );
             }
-
-
-
+            else
+            {
+                ProcessData(reloadcolumns, reloaddata);
+                DoAfterRefresh();
+                bRefreshing = false;
+                IsReady = true;
+                
+                Loading.BeginAnimation(Label.OpacityProperty, null);
+                Loading.Visibility = Visibility.Collapsed;
+            }
+            
             if (cursor != null)
             {
                 cursor.Dispose();