|
@@ -188,7 +188,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
DataGrid.MouseRightButtonUp += DataGrid_MouseRightButtonUp;
|
|
|
DataGrid.KeyUp += DataGrid_KeyUp;
|
|
|
DataGrid.PreviewGotKeyboardFocus += DataGrid_PreviewGotKeyboardFocus;
|
|
|
- //DataGrid.SelectionController = new GridSelectionControllerExt(DataGrid);
|
|
|
+ DataGrid.SelectionController = new GridSelectionControllerExt(DataGrid, this);
|
|
|
|
|
|
DataGrid.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Visible);
|
|
|
|
|
@@ -212,6 +212,30 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
//DataGrid.CellRenderers.Add("TextBox", new CustomTextCellRenderer(this));
|
|
|
}
|
|
|
|
|
|
+ public class GridSelectionControllerExt : GridSelectionController
|
|
|
+ {
|
|
|
+ private DynamicGridGridUIComponent<T> Grid;
|
|
|
+
|
|
|
+ public GridSelectionControllerExt(SfDataGrid datagrid, DynamicGridGridUIComponent<T> grid)
|
|
|
+ : base(datagrid)
|
|
|
+ {
|
|
|
+ Grid = grid;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool HandleKeyDown(KeyEventArgs args)
|
|
|
+ {
|
|
|
+ if (args.Key == Key.Escape)
|
|
|
+ {
|
|
|
+ Grid.CancelEdit();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return base.HandleKeyDown(args);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//private class CustomTextCellRenderer : GridCellTextBoxRenderer
|
|
|
//{
|
|
|
// private DynamicGridGridUIComponent<T> Component;
|
|
@@ -1434,6 +1458,21 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void UpdateRow(CoreRow row, DataRow dataRow)
|
|
|
+ {
|
|
|
+ foreach(var (key, value) in row)
|
|
|
+ {
|
|
|
+ var datacolname = key.Replace(".", "_");
|
|
|
+ var dataValue = dataRow[datacolname];
|
|
|
+ if (!Equals(dataValue, value) && !(value is null && dataValue == DBNull.Value))
|
|
|
+ {
|
|
|
+ dataRow[datacolname] = value ?? DBNull.Value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (var i = 0; i < ActionColumns.Count; i++)
|
|
|
+ dataRow[$"ActionColumn{i}"] = ActionColumns[i].Data(row);
|
|
|
+ }
|
|
|
+
|
|
|
void IDynamicGridUIComponent<T>.UpdateRow(CoreRow row)
|
|
|
{
|
|
|
var dataRow = GetDataRow(row);
|
|
@@ -1567,6 +1606,18 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
bChanged = true;
|
|
|
}
|
|
|
|
|
|
+ private void CancelEdit()
|
|
|
+ {
|
|
|
+ var obj = _editingObject;
|
|
|
+ bChanged = false;
|
|
|
+ _editingObject = null;
|
|
|
+ DataGrid.SelectionController.CurrentCellManager.EndEdit(false);
|
|
|
+ if(obj is not null)
|
|
|
+ {
|
|
|
+ UpdateRow(obj.Row, obj.DataRow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void DataGrid_CurrentCellDropDownSelectionChanged(object? sender,
|
|
|
CurrentCellDropDownSelectionChangedEventArgs e)
|
|
|
{
|
|
@@ -1646,6 +1697,13 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
e.Handled = true;
|
|
|
}
|
|
|
}
|
|
|
+ else if(e.Key == Key.Escape)
|
|
|
+ {
|
|
|
+ if (Parent.IsDirectEditMode())
|
|
|
+ {
|
|
|
+ bChanged = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endregion
|