|
@@ -58,11 +58,11 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
{
|
|
|
_parent = value;
|
|
|
|
|
|
- CellBackgroundConverter = new DynamicGridGridCellStyleConverter<System.Windows.Media.Brush?>(Parent, GetCellBackground);
|
|
|
- CellForegroundConverter = new DynamicGridGridCellStyleConverter<System.Windows.Media.Brush?>(Parent, GetCellForeground);
|
|
|
- CellFontSizeConverter = new DynamicGridGridCellStyleConverter<double?>(Parent, GetCellFontSize);
|
|
|
- CellFontStyleConverter = new DynamicGridGridCellStyleConverter<System.Windows.FontStyle?>(Parent, GetCellFontStyle);
|
|
|
- CellFontWeightConverter = new DynamicGridGridCellStyleConverter<System.Windows.FontWeight?>(Parent, GetCellFontWeight);
|
|
|
+ CellBackgroundConverter = new CellStyleConverter<System.Windows.Media.Brush?>(this, GetCellBackground);
|
|
|
+ CellForegroundConverter = new CellStyleConverter<System.Windows.Media.Brush?>(this, GetCellForeground);
|
|
|
+ CellFontSizeConverter = new CellStyleConverter<double?>(this, GetCellFontSize);
|
|
|
+ CellFontStyleConverter = new CellStyleConverter<System.Windows.FontStyle?>(this, GetCellFontStyle);
|
|
|
+ CellFontWeightConverter = new CellStyleConverter<System.Windows.FontWeight?>(this, GetCellFontWeight);
|
|
|
|
|
|
DataGrid.RowStyleSelector = Parent.RowStyleSelector;
|
|
|
DataGrid.TableSummaryRowStyleSelector = new SummaryRowStyleSelector(GetSummaryRowStyle);
|
|
@@ -273,8 +273,6 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
|
|
|
return result.ToArray();
|
|
|
}
|
|
|
-
|
|
|
- public CoreRow GetVisibleRow(int index) => _rowMap.Values.ToArray()[index];
|
|
|
|
|
|
private void SetSelectedRows(CoreRow[] rows)
|
|
|
{
|
|
@@ -283,7 +281,6 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
var table = DataGridItems;
|
|
|
if(table is null) return;
|
|
|
|
|
|
-
|
|
|
var dataRows = rows.Select(x => _rowMap.FirstOrDefault(y => x == y.Value).Key);
|
|
|
if (!Parent.Options.MultiSelect)
|
|
|
{
|
|
@@ -689,11 +686,56 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
|
|
|
#region Styles
|
|
|
|
|
|
- private DynamicGridGridCellStyleConverter<System.Windows.Media.Brush?> CellBackgroundConverter = null!;
|
|
|
- private DynamicGridGridCellStyleConverter<System.Windows.Media.Brush?> CellForegroundConverter = null!;
|
|
|
- private DynamicGridGridCellStyleConverter<double?> CellFontSizeConverter = null!;
|
|
|
- private DynamicGridGridCellStyleConverter<System.Windows.FontStyle?> CellFontStyleConverter = null!;
|
|
|
- private DynamicGridGridCellStyleConverter<System.Windows.FontWeight?> CellFontWeightConverter = null!;
|
|
|
+ private class CellStyleConverter<TValue>(DynamicGridGridUIComponent component, Func<CoreRow, DynamicColumnBase, TValue> converter) : IValueConverter
|
|
|
+ {
|
|
|
+ private readonly DynamicGridGridUIComponent _component = component ?? throw new ArgumentNullException(nameof(component));
|
|
|
+
|
|
|
+ private readonly Func<CoreRow, DynamicColumnBase, TValue> _converter = converter ?? throw new ArgumentNullException(nameof(converter));
|
|
|
+
|
|
|
+ private CoreRow? GetRow(object item)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (item is DataRowView row)
|
|
|
+ {
|
|
|
+ return component.GetRow(row.Row);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
|
+ {
|
|
|
+ var row = GetRow(value);
|
|
|
+ if (row == null)
|
|
|
+ return DependencyProperty.UnsetValue;
|
|
|
+
|
|
|
+ var param = parameter as DynamicGridCellStyleParameters;
|
|
|
+ if (param == null)
|
|
|
+ return DependencyProperty.UnsetValue;
|
|
|
+
|
|
|
+ //var column = parameter as DynamicColumnBase;
|
|
|
+ //if (column is null)
|
|
|
+ // return DependencyProperty.UnsetValue;
|
|
|
+
|
|
|
+ return _converter.Invoke(row,param.Column) ?? param.DefaultValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
|
+ {
|
|
|
+ throw new NotSupportedException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private CellStyleConverter<System.Windows.Media.Brush?> CellBackgroundConverter = null!;
|
|
|
+ private CellStyleConverter<System.Windows.Media.Brush?> CellForegroundConverter = null!;
|
|
|
+ private CellStyleConverter<double?> CellFontSizeConverter = null!;
|
|
|
+ private CellStyleConverter<System.Windows.FontStyle?> CellFontStyleConverter = null!;
|
|
|
+ private CellStyleConverter<System.Windows.FontWeight?> CellFontWeightConverter = null!;
|
|
|
|
|
|
protected virtual Brush? GetCellSelectionForegroundBrush() => DynamicGridUtils.SelectionForeground;
|
|
|
protected virtual Brush? GetCellSelectionBackgroundBrush() => DynamicGridUtils.SelectionBackground;
|
|
@@ -1502,22 +1544,6 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
{
|
|
|
AddRows(page, false);
|
|
|
}
|
|
|
-
|
|
|
- // public CoreRow DataRowIndexToCoreRow(int index)
|
|
|
- // {
|
|
|
- // var map = _rowMap.FirstOrDefault(x => x.Value.Index == row.Index);
|
|
|
- // if (!Equals(map,default(KeyValuePair<DataRow,CoreRow>)))
|
|
|
- // {
|
|
|
- // //var datarow = table.Rows[row.Index];
|
|
|
- // for (var i = 0; i < rowdata.Count; i++)
|
|
|
- // map.Key[i] = rowdata[i] ?? DBNull.Value;
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- //
|
|
|
- // }
|
|
|
- //
|
|
|
- // }
|
|
|
|
|
|
public void InvalidateRow(CoreRow row)
|
|
|
{
|
|
@@ -1533,17 +1559,13 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
foreach (var ac in ActionColumns)
|
|
|
rowdata.Add(ac.Data(row));
|
|
|
|
|
|
-
|
|
|
- var map = _rowMap.FirstOrDefault(x => x.Value.Index == row.Index);
|
|
|
- if (!Equals(map,default(KeyValuePair<DataRow,CoreRow>)))
|
|
|
- {
|
|
|
- //var datarow = table.Rows[row.Index];
|
|
|
- for (var i = 0; i < rowdata.Count; i++)
|
|
|
- map.Key[i] = rowdata[i] ?? DBNull.Value;
|
|
|
- }
|
|
|
- else
|
|
|
+ var dataRow = GetDataRow(row);
|
|
|
+ if(dataRow is not null)
|
|
|
{
|
|
|
-
|
|
|
+ for(var i = 0; i < rowdata.Count; ++i)
|
|
|
+ {
|
|
|
+ dataRow[i] = rowdata[i] ?? DBNull.Value;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
_invalidating = false;
|
|
@@ -1605,7 +1627,7 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
|
|
|
protected DirectEditingObject EnsureEditingObject(CoreRow row)
|
|
|
{
|
|
|
- _editingObject ??= new(GetEditingObject(row), row, DataGridItems?.Rows[row.Index]);
|
|
|
+ _editingObject ??= new(GetEditingObject(row), row, GetDataRow(row));
|
|
|
return _editingObject;
|
|
|
}
|
|
|
|
|
@@ -1616,7 +1638,14 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
|
|
|
private DataRow? GetDataRow(CoreRow row)
|
|
|
{
|
|
|
- return DataGridItems?.Rows[row.Index];
|
|
|
+ foreach(var (key, value) in _rowMap)
|
|
|
+ {
|
|
|
+ if(value == row)
|
|
|
+ {
|
|
|
+ return key;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
void IDynamicGridUIComponent.UpdateCell(CoreRow row, string column, object? value)
|
|
@@ -1701,12 +1730,8 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
Parent.UpdateData(coreRow, column, updates);
|
|
|
}
|
|
|
|
|
|
- private void UpdateData(int rowIndex, int columnIndex)
|
|
|
+ private void UpdateData(DataRow row, int columnIndex)
|
|
|
{
|
|
|
- var table = DataGridItems;
|
|
|
- if (table is null)
|
|
|
- return;
|
|
|
-
|
|
|
if (GetColumn(columnIndex) is DynamicGridColumn gridcol)
|
|
|
{
|
|
|
var datacol = Parent.Data.Columns.FirstOrDefault(x => x.ColumnName.Equals(gridcol.ColumnName));
|
|
@@ -1714,7 +1739,7 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
{
|
|
|
var datacolindex = Parent.Data.Columns.IndexOf(datacol);
|
|
|
|
|
|
- var value = table.Rows[rowIndex][datacolindex];
|
|
|
+ var value = row[datacolindex];
|
|
|
if (value is DBNull)
|
|
|
value = CoreUtils.GetDefault(datacol.DataType);
|
|
|
|
|
@@ -1752,9 +1777,9 @@ public class DynamicGridGridUIComponent : IDynamicGridUIComponent, IDynamicGridG
|
|
|
|
|
|
private void DataGrid_CurrentCellEndEdit(object? sender, CurrentCellEndEditEventArgs e)
|
|
|
{
|
|
|
- if (_editingObject is not null && bChanged)
|
|
|
+ if (_editingObject is not null && bChanged && _editingObject.DataRow is not null)
|
|
|
{
|
|
|
- UpdateData(_editingObject.Row.Index, e.RowColumnIndex.ColumnIndex);
|
|
|
+ UpdateData(_editingObject.DataRow, e.RowColumnIndex.ColumnIndex);
|
|
|
}
|
|
|
if (bChanged)
|
|
|
Parent.DoChanged();
|
|
@@ -1953,11 +1978,6 @@ public class DynamicGridGridUIComponent<T> : DynamicGridGridUIComponent, IDynami
|
|
|
return Parent.LoadItem(row);
|
|
|
}
|
|
|
|
|
|
- private DataRow? GetDataRow(CoreRow row)
|
|
|
- {
|
|
|
- return DataGridItems?.Rows[row.Index];
|
|
|
- }
|
|
|
-
|
|
|
protected override void DoEntityChanged(IDynamicColumnBase column, DynamicColumnEntityChangedEventArgs args)
|
|
|
{
|
|
|
base.DoEntityChanged(column, args);
|