|
@@ -3,7 +3,9 @@ using InABox.Core;
|
|
|
using InABox.WPF;
|
|
|
using org.omg.PortableInterceptor;
|
|
|
using Syncfusion.Data;
|
|
|
+using Syncfusion.Data.Extensions;
|
|
|
using Syncfusion.UI.Xaml.Grid;
|
|
|
+using Syncfusion.UI.Xaml.Grid.Cells;
|
|
|
using Syncfusion.UI.Xaml.Grid.Helpers;
|
|
|
using Syncfusion.UI.Xaml.ScrollAxis;
|
|
|
using Syncfusion.Windows.Shared;
|
|
@@ -105,7 +107,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
|
|
|
DataGrid.CurrentCellBeginEdit += DataGrid_CurrentCellBeginEdit;
|
|
|
DataGrid.CurrentCellEndEdit += DataGrid_CurrentCellEndEdit;
|
|
|
- DataGrid.CurrentCellValueChanged += DataGrid_CurrentCellValueChanged;
|
|
|
DataGrid.CurrentCellDropDownSelectionChanged += DataGrid_CurrentCellDropDownSelectionChanged;
|
|
|
DataGrid.PreviewKeyUp += DataGrid_PreviewKeyUp;
|
|
|
|
|
@@ -114,8 +115,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
DataGrid.Background = new SolidColorBrush(Colors.DimGray);
|
|
|
DataGrid.AutoGenerateColumns = false;
|
|
|
DataGrid.ColumnSizer = GridLengthUnitType.AutoLastColumnFill;
|
|
|
- DataGrid.SelectionForegroundBrush = DynamicGridUtils.SelectionForeground;
|
|
|
- DataGrid.RowSelectionBrush = DynamicGridUtils.SelectionBackground;
|
|
|
+ DataGrid.SelectionForegroundBrush = GetCellSelectionForegroundBrush() ?? DynamicGridUtils.SelectionForeground;
|
|
|
+ DataGrid.RowSelectionBrush = GetCellSelectionBackgroundBrush() ?? DynamicGridUtils.SelectionBackground;
|
|
|
|
|
|
DataGrid.AllowDraggingRows = false;
|
|
|
DataGrid.Drop += DataGrid_Drop;
|
|
@@ -165,6 +166,63 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
//DataGrid.HeaderStyle = headstyle;
|
|
|
|
|
|
DataGrid.SizeChanged += DataGrid_SizeChanged;
|
|
|
+
|
|
|
+ //DataGrid.CellRenderers.Remove("Numeric");
|
|
|
+ //DataGrid.CellRenderers.Add("Numeric", new CustomNumericCellRenderer(this));
|
|
|
+ //DataGrid.CellRenderers.Remove("TextBox");
|
|
|
+ //DataGrid.CellRenderers.Add("TextBox", new CustomTextCellRenderer(this));
|
|
|
+ }
|
|
|
+
|
|
|
+ //private class CustomTextCellRenderer : GridCellTextBoxRenderer
|
|
|
+ //{
|
|
|
+ // private DynamicGridGridUIComponent<T> Component;
|
|
|
+
|
|
|
+ // public CustomTextCellRenderer(DynamicGridGridUIComponent<T> component)
|
|
|
+ // {
|
|
|
+ // Component = component;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public override void OnInitializeEditElement(DataColumnBase dataColumn, TextBox uiElement, object dataContext)
|
|
|
+ // {
|
|
|
+ // base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
|
|
|
+ // uiElement.TextChanged += UiElement_TextChanged;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // private void UiElement_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ // {
|
|
|
+ // throw new NotImplementedException();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // private void UiElement_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
+ // {
|
|
|
+ // Component.ChangeValue(e.OldValue, e.NewValue);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //private class CustomNumericCellRenderer : GridCellNumericRenderer
|
|
|
+ //{
|
|
|
+ // private DynamicGridGridUIComponent<T> Component;
|
|
|
+
|
|
|
+ // public CustomNumericCellRenderer(DynamicGridGridUIComponent<T> component)
|
|
|
+ // {
|
|
|
+ // Component = component;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public override void OnInitializeEditElement(DataColumnBase dataColumn, DoubleTextBox uiElement, object dataContext)
|
|
|
+ // {
|
|
|
+ // base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
|
|
|
+ // uiElement.ValueChanged += UiElement_ValueChanged;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // private void UiElement_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
+ // {
|
|
|
+ // Component.ChangeValue(e.OldValue, e.NewValue);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ private void ChangeValue(object oldValue, object newValue)
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void ColumnsMenu_ContextMenuOpening(object sender, RoutedEventArgs e)
|
|
@@ -570,6 +628,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
DataGrid.ScrollInView(new RowColumnIndex(rowIdx, 0));
|
|
|
}
|
|
|
|
|
|
+ protected virtual Brush? GetCellSelectionForegroundBrush() => DynamicGridUtils.SelectionForeground;
|
|
|
+ protected virtual Brush? GetCellSelectionBackgroundBrush() => DynamicGridUtils.SelectionBackground;
|
|
|
protected virtual Brush? GetCellBackground(CoreRow row, DynamicColumnBase column) => null;
|
|
|
protected virtual Brush? GetCellForeground(CoreRow row, DynamicColumnBase column) => null;
|
|
|
protected virtual double? GetCellFontSize(CoreRow row, DynamicColumnBase column) => null;
|
|
@@ -578,6 +638,70 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
|
|
|
#region Columns
|
|
|
|
|
|
+ private class StackedHeaderRenderer : GridStackedHeaderCellRenderer
|
|
|
+ {
|
|
|
+ private Style Style;
|
|
|
+
|
|
|
+ public StackedHeaderRenderer()
|
|
|
+ {
|
|
|
+ var headstyle = new Style(typeof(GridStackedHeaderCellControl));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0, 0.0, 0, 0)));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
|
|
|
+
|
|
|
+ Style = headstyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void OnInitializeEditElement(DataColumnBase dataColumn, GridStackedHeaderCellControl uiElement, object dataContext)
|
|
|
+ {
|
|
|
+ uiElement.Style = Style;
|
|
|
+ base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadStackedHeaders(DynamicGridColumnGroupings groupings)
|
|
|
+ {
|
|
|
+ DataGrid.StackedHeaderRows.Clear();
|
|
|
+ foreach(var grouping in groupings)
|
|
|
+ {
|
|
|
+ var row = new StackedHeaderRow();
|
|
|
+ var i = 0;
|
|
|
+ foreach(var group in grouping.Groups)
|
|
|
+ {
|
|
|
+ var start = Math.Max(i, ColumnList.IndexOf(group.StartColumn));
|
|
|
+ var end = Math.Max(start, ColumnList.IndexOf(group.EndColumn));
|
|
|
+
|
|
|
+ if(end < start)
|
|
|
+ {
|
|
|
+ i = end + 1;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ var cols = Enumerable.Range(start, end - start + 1).Select(i => DataGrid.Columns[i]).ToArray();
|
|
|
+
|
|
|
+ var stackedColumn = new StackedColumn
|
|
|
+ {
|
|
|
+ HeaderText = group.Header,
|
|
|
+ ChildColumns = string.Join(',', cols.Select(x => x.MappingName))
|
|
|
+ };
|
|
|
+
|
|
|
+ row.StackedColumns.Add(stackedColumn);
|
|
|
+
|
|
|
+ i = end + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ DataGrid.StackedHeaderRows.Add(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(groupings.Count > 0)
|
|
|
+ {
|
|
|
+ DataGrid.CellRenderers.Remove("StackedHeader");
|
|
|
+ DataGrid.CellRenderers.Add("StackedHeader", new StackedHeaderRenderer());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private readonly List<DynamicColumnBase> ColumnList = new();
|
|
|
|
|
|
private List<DynamicActionColumn> ActionColumns = new();
|
|
@@ -602,6 +726,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private ObservableCollection<ISummaryColumn> Summaries = new();
|
|
|
+
|
|
|
private void LoadActionColumns(DynamicActionColumnPosition position)
|
|
|
{
|
|
|
for (var i = 0; i < ActionColumns.Count; i++)
|
|
@@ -613,6 +739,14 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
var sColName = string.Format("ActionColumn{0}", i);
|
|
|
gridRowResizingOptions.ExcludeColumns.Add(sColName);
|
|
|
|
|
|
+ var summary = column.Summary();
|
|
|
+ if (summary != null)
|
|
|
+ {
|
|
|
+ summary.Name = sColName;
|
|
|
+ summary.MappingName = sColName;
|
|
|
+ Summaries.Add(summary);
|
|
|
+ }
|
|
|
+
|
|
|
if (column is DynamicImageColumn imgcol)
|
|
|
{
|
|
|
var newcol = new GridImageColumn();
|
|
@@ -644,7 +778,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
{
|
|
|
//headstyle.Setters.Add(new Setter(LayoutTransformProperty, new RotateTransform(270.0F)));
|
|
|
headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0, 0.0, 0, 0)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 0.75, 0.75)));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
|
|
|
if (imgcol.VerticalHeader)
|
|
|
headstyle.Setters.Add(new Setter(Control.TemplateProperty,
|
|
|
Application.Current.Resources["VerticalColumnHeader"] as ControlTemplate));
|
|
@@ -710,7 +844,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
|
|
|
headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
|
|
|
headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0, 0.0, 0, 0)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 0.75, 0.75)));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
|
|
|
if (txtCol.VerticalHeader)
|
|
|
{
|
|
|
headstyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Left));
|
|
@@ -761,9 +895,10 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
else if (column is DynamicTemplateColumn tmplCol)
|
|
|
{
|
|
|
var newcol = new GridTemplateColumn();
|
|
|
- newcol.CellTemplateSelector = new TemplateColumnSelector() { DataTemplate = tmplCol.Template };
|
|
|
+ newcol.CellTemplateSelector = new TemplateColumnSelector(this, tmplCol.Template);
|
|
|
newcol.AllowEditing = false;
|
|
|
newcol.UpdateTrigger = UpdateSourceTrigger.PropertyChanged;
|
|
|
+ newcol.MappingName = sColName;
|
|
|
|
|
|
newcol.Width = tmplCol.Width;
|
|
|
newcol.ColumnSizer = GridLengthUnitType.None;
|
|
@@ -783,10 +918,31 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
headstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
|
|
|
headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
|
|
|
headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
|
|
|
- headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, -0.75, 0, 0.75)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.75)));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
|
|
|
+ headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0)));
|
|
|
newcol.HeaderStyle = headstyle;
|
|
|
|
|
|
+ var cellstyle = new Style();
|
|
|
+ cellstyle.Setters.Add(new Setter(Control.BackgroundProperty,
|
|
|
+ new Binding()
|
|
|
+ {
|
|
|
+ Path = new PropertyPath("."), Converter = CellBackgroundConverter,
|
|
|
+ ConverterParameter = column
|
|
|
+ }));
|
|
|
+ cellstyle.Setters.Add(new Setter(Control.ForegroundProperty,
|
|
|
+ new Binding()
|
|
|
+ { Converter = CellForegroundConverter, ConverterParameter = column }));
|
|
|
+ cellstyle.Setters.Add(new Setter(Control.FontSizeProperty,
|
|
|
+ new Binding()
|
|
|
+ { Converter = CellFontSizeConverter, ConverterParameter = column }));
|
|
|
+ cellstyle.Setters.Add(new Setter(Control.FontStyleProperty,
|
|
|
+ new Binding()
|
|
|
+ { Converter = CellFontStyleConverter, ConverterParameter = column }));
|
|
|
+ cellstyle.Setters.Add(new Setter(Control.FontWeightProperty,
|
|
|
+ new Binding()
|
|
|
+ { Converter = CellFontWeightConverter, ConverterParameter = column }));
|
|
|
+ newcol.CellStyle = cellstyle;
|
|
|
+
|
|
|
DataGrid.Columns.Add(newcol);
|
|
|
ColumnList.Add(column);
|
|
|
}
|
|
@@ -794,12 +950,41 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public class TemplateColumnSelector : DataTemplateSelector
|
|
|
+ public class TemplateColumnSelector(DynamicGridGridUIComponent<T> parent, Func<CoreRow, FrameworkElement?> dataTemplate) : DataTemplateSelector
|
|
|
{
|
|
|
- public Func<FrameworkElement> DataTemplate { get; init; }
|
|
|
-
|
|
|
- public override DataTemplate SelectTemplate(object item, DependencyObject container)
|
|
|
- => TemplateGenerator.CreateDataTemplate(DataTemplate);
|
|
|
+ public Func<CoreRow, FrameworkElement?> DataTemplate { get; init; } = dataTemplate;
|
|
|
+
|
|
|
+ public DynamicGridGridUIComponent<T> Parent { get; init; } = parent;
|
|
|
+
|
|
|
+ public override DataTemplate? SelectTemplate(object item, DependencyObject container)
|
|
|
+ {
|
|
|
+ if (item is not DataRowView) return null;
|
|
|
+
|
|
|
+ CoreRow? row;
|
|
|
+ if(item is DataRowView view && Parent.DataGridItems is DataTable table)
|
|
|
+ {
|
|
|
+ var rowIdx = table.Rows.IndexOf(view.Row);
|
|
|
+ if (rowIdx < 0)
|
|
|
+ {
|
|
|
+ row = null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ row = Parent.Parent.Data.Rows[rowIdx];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ row = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (row is null) return null;
|
|
|
+
|
|
|
+ return TemplateGenerator.CreateDataTemplate(() =>
|
|
|
+ {
|
|
|
+ return DataTemplate(row);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void ApplyFilterStyle(GridColumn column, bool filtering, bool isactioncolumn)
|
|
@@ -831,11 +1016,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
column.FilterRowCellStyle = filterstyle;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void LoadDataColumns(DynamicGridColumns columns)
|
|
|
{
|
|
|
- var Summaries = new ObservableCollection<ISummaryColumn>();
|
|
|
-
|
|
|
foreach (var column in columns)
|
|
|
{
|
|
|
if (this.CreateEditorColumn(column, out var newcol, out var prop))
|
|
@@ -931,6 +1113,10 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadSummaries()
|
|
|
+ {
|
|
|
if (Summaries.Any())
|
|
|
{
|
|
|
DataGrid.CellRenderers.Remove("TableSummary");
|
|
@@ -945,7 +1131,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void RefreshColumns(DynamicGridColumns columns, DynamicActionColumns actionColumns)
|
|
|
+ public void RefreshColumns(DynamicGridColumns columns, DynamicActionColumns actionColumns, DynamicGridColumnGroupings groupings)
|
|
|
{
|
|
|
// Yo, please don't remove this.
|
|
|
// The issue was when we were dynamically adding ActionColumns, and if we had to remove and then re-add them, we were getting massive performance hits
|
|
@@ -964,9 +1150,12 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
|
|
|
ActionColumns = actionColumns.ToList();
|
|
|
|
|
|
+ Summaries.Clear();
|
|
|
LoadActionColumns(DynamicActionColumnPosition.Start);
|
|
|
LoadDataColumns(columns);
|
|
|
LoadActionColumns(DynamicActionColumnPosition.End);
|
|
|
+ LoadSummaries();
|
|
|
+ LoadStackedHeaders(groupings);
|
|
|
|
|
|
DataGrid.Columns.Resume();
|
|
|
DataGrid.RefreshColumns();
|
|
@@ -993,10 +1182,12 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
|
|
|
#region Data
|
|
|
|
|
|
+ private bool _invalidating = false;
|
|
|
+
|
|
|
public void BeforeRefresh()
|
|
|
{
|
|
|
- DataGrid.SelectionForegroundBrush = DynamicGridUtils.SelectionForeground;
|
|
|
- DataGrid.RowSelectionBrush = DynamicGridUtils.SelectionBackground;
|
|
|
+ DataGrid.SelectionForegroundBrush = GetCellSelectionForegroundBrush();
|
|
|
+ DataGrid.RowSelectionBrush = GetCellSelectionBackgroundBrush();
|
|
|
}
|
|
|
|
|
|
public void RefreshData(CoreTable data)
|
|
@@ -1029,6 +1220,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
result.Rows.Add(newrow);
|
|
|
}
|
|
|
|
|
|
+ result.ColumnChanged += Result_ColumnChanged;
|
|
|
+
|
|
|
//int rowIndex = DataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex;
|
|
|
//int columnIndex = DataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex;
|
|
|
//int scrollRowIndex = DataGrid.GetVisualContainer().ScrollRows.LastBodyVisibleLineIndex;
|
|
@@ -1047,6 +1240,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ _invalidating = true;
|
|
|
+
|
|
|
var rowdata = new List<object?>(row.Values);
|
|
|
foreach (var ac in ActionColumns)
|
|
|
rowdata.Add(ac.Data(row));
|
|
@@ -1054,6 +1249,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
var datarow = DataGridItems.Rows[row.Index];
|
|
|
for (var i = 0; i < rowdata.Count; i++)
|
|
|
datarow[i] = rowdata[i] ?? DBNull.Value;
|
|
|
+ _invalidating = false;
|
|
|
//datarow.ItemArray = rowdata.ToArray();
|
|
|
}
|
|
|
|
|
@@ -1224,22 +1420,46 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
bChanged = false;
|
|
|
}
|
|
|
|
|
|
- private void DataGrid_CurrentCellValueChanged(object? sender, CurrentCellValueChangedEventArgs e)
|
|
|
+ private void Result_ColumnChanged(object sender, DataColumnChangeEventArgs e)
|
|
|
{
|
|
|
- var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
|
|
|
- // 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
|
|
|
+ if (_invalidating) return;
|
|
|
+ if (sender is not DataTable table) return;
|
|
|
+
|
|
|
+ var rowIdx = table.Rows.IndexOf(e.Row);
|
|
|
+ if (rowIdx < 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var row = Parent.Data.Rows[rowIdx];
|
|
|
|
|
|
- if (row is null) return;
|
|
|
+ var colIdx = table.Columns.IndexOf(e.Column);
|
|
|
+ if (colIdx < 0 || colIdx >= Parent.Data.Columns.Count)
|
|
|
+ return;
|
|
|
|
|
|
- if (e.Column is GridCheckBoxColumn)
|
|
|
+ var data = Parent.Data;
|
|
|
+
|
|
|
+ var dataCol = Parent.Data.Columns[colIdx];
|
|
|
+ var col = ColumnList.OfType<DynamicGridColumn>()
|
|
|
+ .FirstOrDefault(x => x.ColumnName.Equals(dataCol.ColumnName));
|
|
|
+
|
|
|
+ if (col is null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (col is DynamicGridCheckBoxColumn<T>)
|
|
|
{
|
|
|
EnsureEditingObject(row);
|
|
|
- }
|
|
|
+ if(_editingObject is not null)
|
|
|
+ {
|
|
|
+ var value = e.Row[e.Column!];
|
|
|
+ if (value is DBNull)
|
|
|
+ value = CoreUtils.GetDefault(dataCol.DataType);
|
|
|
+
|
|
|
+ _invalidating = true;
|
|
|
+ UpdateData(dataCol.ColumnName, new Dictionary<CoreColumn, object?>() { { dataCol, value } });
|
|
|
+ _invalidating = false;
|
|
|
+ }
|
|
|
|
|
|
- if (_editingObject is not null)
|
|
|
- UpdateData(_editingObject.Row.Index, e.RowColumnIndex.ColumnIndex);
|
|
|
- if (e.Column is GridCheckBoxColumn)
|
|
|
_editingObject = null;
|
|
|
+ }
|
|
|
if (_editingObject is not null)
|
|
|
bChanged = true;
|
|
|
}
|