Browse Source

Fixed DBNull issues

Kenric Nugteren 1 year ago
parent
commit
ce33a03925
2 changed files with 16 additions and 5 deletions
  1. 10 5
      InABox.Core/BaseObject.cs
  2. 6 0
      inabox.wpf/DynamicGrid/DynamicGrid.cs

+ 10 - 5
InABox.Core/BaseObject.cs

@@ -109,13 +109,18 @@ namespace InABox.Core
 
             if (!bApplyingChanges)
             {
-                bApplyingChanges = true;
-
-                DoPropertyChanged(name, before, after);
+                try
+                {
+                    bApplyingChanges = true;
 
-                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+                    DoPropertyChanged(name, before, after);
 
-                bApplyingChanges = false;
+                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+                }
+                finally
+                {
+                    bApplyingChanges = false;
+                }
             }
         }
 

+ 6 - 0
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -21,6 +21,7 @@ using System.Windows.Threading;
 using InABox.Clients;
 using InABox.Core;
 using InABox.WPF;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
 using Microsoft.Xaml.Behaviors;
 using Syncfusion.Data;
 using Syncfusion.DocIO.ReaderWriter.DataStreamParser.Escher;
@@ -977,6 +978,7 @@ namespace InABox.DynamicGrid
 
         private void DataGrid_CurrentCellValueChanged(object? sender, CurrentCellValueChangedEventArgs e)
         {
+            // Are we sure that this function is ever useful? It seems that since the data in the grid hasn't been updated by this point, this function is essentially useless (the data is updated in EndEdit). Probably need to check the GridCheckBoxColumn
             var headerrows = HasOption(DynamicGridOption.FilterRows) ? 2 : 1;
             if (e.RowColumnIndex.RowIndex < headerrows)
                 return;
@@ -1153,6 +1155,10 @@ namespace InABox.DynamicGrid
             var colno = DataGridItems.Columns.IndexOf(mappedname);
             var column = Data.Columns[colno];
             var value = DataGridItems.Rows[iRow][mappedname];
+            if(value is DBNull)
+            {
+                value = CoreUtils.GetDefault(column.DataType);
+            }
             
             UpdateData(new Dictionary<CoreColumn, object?>() { { column, value } });