DynamicGridTreeUIComponent.cs 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853
  1. using InABox.Clients;
  2. using InABox.Core;
  3. using InABox.Wpf;
  4. using InABox.WPF;
  5. using Syncfusion.Data;
  6. using Syncfusion.UI.Xaml.Grid;
  7. using Syncfusion.UI.Xaml.ScrollAxis;
  8. using Syncfusion.UI.Xaml.TreeGrid;
  9. using Syncfusion.UI.Xaml.TreeGrid.Helpers;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Linq;
  14. using System.Linq.Expressions;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Input;
  21. using System.Windows.Media;
  22. using System.Windows.Media.Imaging;
  23. using Syncfusion.UI.Xaml.TreeGrid.Filtering;
  24. using Syncfusion.UI.Xaml.TreeGrid.Cells;
  25. using System.Windows.Controls.Primitives;
  26. namespace InABox.DynamicGrid;
  27. public enum DynamicTreeGridLines
  28. {
  29. Both,
  30. Horizontal,
  31. Vertical,
  32. None
  33. }
  34. public enum DynamicTreeGridExpandMode
  35. {
  36. All,
  37. Root,
  38. None
  39. }
  40. public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynamicGridGridUIComponent<T>
  41. where T : BaseObject, new()
  42. {
  43. private IDynamicGridUIComponentParent<T> _parent;
  44. public IDynamicGridUIComponentParent<T> Parent
  45. {
  46. get => _parent;
  47. set
  48. {
  49. _parent = value;
  50. CellBackgroundConverter = new DynamicGridCellStyleConverter<System.Windows.Media.Brush?>(Parent, GetCellBackground);
  51. CellForegroundConverter = new DynamicGridCellStyleConverter<System.Windows.Media.Brush?>(Parent, GetCellForeground);
  52. CellFontSizeConverter = new DynamicGridCellStyleConverter<double?>(Parent, GetCellFontSize);
  53. CellFontStyleConverter = new DynamicGridCellStyleConverter<System.Windows.FontStyle?>(Parent, GetCellFontStyle);
  54. CellFontWeightConverter = new DynamicGridCellStyleConverter<System.Windows.FontWeight?>(Parent, GetCellFontWeight);
  55. Parent.AddHiddenColumn(IDColumn.Property);
  56. Parent.AddHiddenColumn(ParentColumn.Property);
  57. }
  58. }
  59. private Column<T> IDColumn;
  60. private Column<T> ParentColumn;
  61. private ContextMenu _menu;
  62. private SfTreeGrid _tree;
  63. private Grid _summaryRow;
  64. private readonly ContextMenu ColumnsMenu;
  65. public event OnContextMenuOpening OnContextMenuOpening;
  66. FrameworkElement IDynamicGridUIComponent<T>.Control => _tree;
  67. private bool _shownumbers = false;
  68. public bool ShowNumbers
  69. {
  70. get => _shownumbers;
  71. set
  72. {
  73. _shownumbers = value;
  74. //_tree.Columns[1].Width = value ? 50 : 0;
  75. }
  76. }
  77. private bool _showHeader = false;
  78. public bool ShowHeader
  79. {
  80. get => _showHeader;
  81. set
  82. {
  83. _showHeader = value;
  84. _tree.HeaderRowHeight = value ? 30 : 0;
  85. }
  86. }
  87. private bool _autoSizeExpander = false;
  88. public bool AutoSizeExpander
  89. {
  90. get => _autoSizeExpander;
  91. set
  92. {
  93. _autoSizeExpander = value;
  94. _tree.AllowAutoSizingExpanderColumn = value;
  95. }
  96. }
  97. private DynamicTreeGridLines _gridLines = DynamicTreeGridLines.Both;
  98. public DynamicTreeGridLines GridLines
  99. {
  100. get => _gridLines;
  101. set
  102. {
  103. _gridLines = value;
  104. _tree.GridLinesVisibility = value switch
  105. {
  106. DynamicTreeGridLines.Both => GridLinesVisibility.Both,
  107. DynamicTreeGridLines.Vertical => GridLinesVisibility.Vertical,
  108. DynamicTreeGridLines.Horizontal => GridLinesVisibility.Horizontal,
  109. _ => GridLinesVisibility.None,
  110. };
  111. }
  112. }
  113. public DynamicTreeGridExpandMode ExpandMode
  114. {
  115. get
  116. {
  117. return _tree.AutoExpandMode switch
  118. {
  119. AutoExpandMode.AllNodesExpanded => DynamicTreeGridExpandMode.All,
  120. AutoExpandMode.RootNodesExpanded => DynamicTreeGridExpandMode.Root,
  121. _ => DynamicTreeGridExpandMode.None,
  122. };
  123. }
  124. set
  125. {
  126. _tree.AutoExpandMode = value switch
  127. {
  128. DynamicTreeGridExpandMode.All => AutoExpandMode.AllNodesExpanded,
  129. DynamicTreeGridExpandMode.Root => AutoExpandMode.RootNodesExpanded,
  130. _ => AutoExpandMode.None
  131. };
  132. }
  133. }
  134. private double minRowHeight = 30D;
  135. private double maxRowHeight = 30D;
  136. public double MinRowHeight
  137. {
  138. get => minRowHeight;
  139. set
  140. {
  141. minRowHeight = value;
  142. CalculateRowHeight();
  143. }
  144. }
  145. public double MaxRowHeight
  146. {
  147. get => maxRowHeight;
  148. set
  149. {
  150. maxRowHeight = value;
  151. CalculateRowHeight();
  152. }
  153. }
  154. #region IDynamicGridGridUIComponent
  155. IList<DynamicColumnBase> IDynamicGridGridUIComponent<T>.ColumnList => ColumnList;
  156. int IDynamicGridGridUIComponent<T>.RowHeight => (int)RowHeight;
  157. #endregion
  158. private DynamicGridCellStyleConverter<System.Windows.Media.Brush?> CellBackgroundConverter;
  159. private DynamicGridCellStyleConverter<System.Windows.Media.Brush?> CellForegroundConverter;
  160. private DynamicGridCellStyleConverter<double?> CellFontSizeConverter;
  161. private DynamicGridCellStyleConverter<System.Windows.FontStyle?> CellFontStyleConverter;
  162. private DynamicGridCellStyleConverter<System.Windows.FontWeight?> CellFontWeightConverter;
  163. public DynamicGridTreeUIComponent(Expression<Func<T, Guid>> idColumn, Expression<Func<T, Guid>> parentIDColumn)
  164. {
  165. IDColumn = new Column<T>(CoreUtils.GetFullPropertyName(idColumn, "."));
  166. ParentColumn = new Column<T>(CoreUtils.GetFullPropertyName(parentIDColumn, "."));
  167. ColumnsMenu = new ContextMenu();
  168. ColumnsMenu.Opened += ColumnsMenu_ContextMenuOpening;
  169. _tree = new SfTreeGrid();
  170. _tree.ChildPropertyName = "Children";
  171. //_tree.ParentPropertyName = "Parent";
  172. _tree.AutoGenerateColumns = false;
  173. ExpandMode = DynamicTreeGridExpandMode.All;
  174. //_tree.NodeCollapsing += (o, e) => { e.Cancel = true; };
  175. //_tree.HeaderRowHeight = 0D;
  176. _tree.HeaderRowHeight = 30;
  177. _tree.HeaderContextMenu = ColumnsMenu;
  178. _tree.SelectionChanging += _tree_SelectionChanging;
  179. _tree.SelectionChanged += _tree_SelectionChanged;
  180. _tree.AllowSelectionOnExpanderClick = false;
  181. _tree.AllowAutoSizingExpanderColumn = false;
  182. _tree.CellTapped += _tree_CellTapped;
  183. _tree.CellDoubleTapped += _tree_CellDoubleTapped;
  184. _tree.KeyUp += _tree_KeyUp;
  185. _tree.Loaded += _tree_Loaded;
  186. _tree.CellToolTipOpening += _tree_CellToolTipOpening;
  187. _menu = new ContextMenu();
  188. var additem = new MenuItem() { Header = "Add Child Folder" };
  189. additem.Click += (o, e) => { DoAddItem((_tree.SelectedItem as CoreTreeNode)!.ID, true); };
  190. _menu.Items.Add(additem);
  191. _tree.ContextMenuOpening += _tree_ContextMenuOpening;
  192. _tree.ContextMenu = _menu;
  193. _tree.Background = new SolidColorBrush(Colors.DimGray);
  194. var cellStyle = new Style(typeof(TreeGridRowControl));
  195. cellStyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.White)));
  196. _tree.RowStyle = cellStyle;
  197. var filterstyle = new Style(typeof(TreeGridFilterControl));
  198. filterstyle.Setters.Add(new Setter(TreeGridFilterControl.SortOptionVisibilityProperty, Visibility.Collapsed));
  199. filterstyle.Setters.Add(new Setter(TreeGridFilterControl.ImmediateUpdateColumnFilterProperty, false));
  200. _tree.FilterPopupStyle = filterstyle;
  201. _tree.FilterChanged += _tree_FilterChanged;
  202. _tree.FilterItemsPopulating += _tree_FilterItemsPopulating;
  203. _tree.FilterLevel = FilterLevel.Extended;
  204. _tree.SelectionForeground = DynamicGridUtils.SelectionForeground;
  205. _tree.SelectionBackground = DynamicGridUtils.SelectionBackground;
  206. _tree.EditTrigger = EditTrigger.OnTap;
  207. _tree.CurrentCellBeginEdit += _tree_CurrentCellBeginEdit;
  208. _tree.CurrentCellEndEdit += _tree_CurrentCellEndEdit;
  209. _tree.CurrentCellDropDownSelectionChanged += _tree_CurrentCellDropDownSelectionChanged;
  210. _tree.PreviewKeyUp += _tree_PreviewKeyUp;
  211. _tree.SelectionController = new TreeGridSelectionControllerExt(_tree, this);
  212. _tree.ColumnSizer = TreeColumnSizer.None;
  213. _tree.RowHeight = 30D;
  214. _tree.SetValue(Grid.RowProperty, 0);
  215. _tree.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Visible);
  216. _tree.AllowDraggingRows = false;
  217. _tree.Drop += _tree_Drop;
  218. _tree.DragOver += _tree_DragOver;
  219. _tree.RowDragDropTemplate = TemplateGenerator.CreateDataTemplate(() =>
  220. {
  221. var border = new Border();
  222. border.Width = 100;
  223. border.Height = 100;
  224. border.BorderBrush = new SolidColorBrush(Colors.Firebrick);
  225. border.Background = new SolidColorBrush(Colors.Red);
  226. border.CornerRadius = new CornerRadius(5);
  227. return border;
  228. });
  229. _tree.SizeChanged += _tree_SizeChanged;
  230. }
  231. private void _tree_Loaded(object sender, RoutedEventArgs e)
  232. {
  233. _summaryRow = new Grid();
  234. _summaryRow.Visibility = Visibility.Collapsed;
  235. var scroll = _tree.FindChild<ScrollViewer>("PART_ScrollViewer");
  236. if(scroll is not null)
  237. {
  238. var grid = scroll.FindVisualChildren<Grid>(recursive: false).FirstOrDefault();
  239. if(grid is not null)
  240. {
  241. var row1 = grid.RowDefinitions[0];
  242. var row2 = grid.RowDefinitions[1];
  243. grid.RowDefinitions.Clear();
  244. grid.RowDefinitions.Add(row1);
  245. var rowDef = grid.AddRow(GridUnitType.Auto);
  246. grid.RowDefinitions.Add(row2);
  247. foreach(var child in grid.Children.OfType<UIElement>())
  248. {
  249. var row = Grid.GetRow(child);
  250. if(row >= 1)
  251. {
  252. Grid.SetRow(child, row + 1);
  253. }
  254. else
  255. {
  256. var rowSpan = Grid.GetRowSpan(child);
  257. if(row + rowSpan >= 1 && child is ScrollBar)
  258. {
  259. Grid.SetRowSpan(child, rowSpan + 1);
  260. }
  261. }
  262. }
  263. var horizontalScrollbar = grid.Children.OfType<ScrollBar>().First(x => x.Orientation == Orientation.Horizontal);
  264. var treeGridPanel = scroll.FindChild<TreeGridPanel>("PART_TreeGridPanel");
  265. var summaryScroll = new ScrollViewer
  266. {
  267. VerticalScrollBarVisibility = ScrollBarVisibility.Hidden,
  268. HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden
  269. };
  270. summaryScroll.Content = _summaryRow;
  271. scroll.ScrollChanged += (o, e) =>
  272. {
  273. summaryScroll.ScrollToHorizontalOffset(scroll.HorizontalOffset);
  274. var panel = treeGridPanel;
  275. };
  276. var transform = new TranslateTransform();
  277. summaryScroll.RenderTransform = transform;
  278. void UpdateSize(double height)
  279. {
  280. var desiredHeight = treeGridPanel.RowHeights.TotalExtent;
  281. if(desiredHeight < height)
  282. {
  283. var diff = height - desiredHeight;
  284. transform.Y = -diff - 1;
  285. }
  286. else
  287. {
  288. transform.Y = 0;
  289. }
  290. }
  291. treeGridPanel.SizeChanged += (o, e) =>
  292. {
  293. UpdateSize(e.NewSize.Height);
  294. };
  295. _tree.FilterChanged += (o, e) =>
  296. {
  297. UpdateSize(treeGridPanel.ActualHeight);
  298. };
  299. grid.AddChild(summaryScroll, 1, 0);
  300. }
  301. }
  302. }
  303. private class TreeGridSelectionControllerExt(SfTreeGrid treeGrid, DynamicGridTreeUIComponent<T> grid) : TreeGridRowSelectionController(treeGrid)
  304. {
  305. private DynamicGridTreeUIComponent<T> Grid = grid;
  306. public override bool HandleKeyDown(KeyEventArgs args)
  307. {
  308. if (args.Key == Key.Escape)
  309. {
  310. Grid.CancelEdit();
  311. return false;
  312. }
  313. else
  314. {
  315. return base.HandleKeyDown(args);
  316. }
  317. }
  318. }
  319. #region Public Interface
  320. public IEnumerable<CoreRow> GetChildren(Guid id)
  321. {
  322. return Nodes.GetChildren(id).Select(x => MapRow(x.Row)).NotNull();
  323. }
  324. #endregion
  325. #region Input
  326. private CoreTreeNode? GetNodeFromIndex(int rowIndex)
  327. {
  328. // Syncfusion has given us the row index, so it also will give us the correct row, after sorting.
  329. // Hence, here we use the syncfusion DataGrid.GetRecordAtRowIndex, which *should* always return a DataRowView.
  330. var row = _tree.GetNodeAtRowIndex(rowIndex);
  331. return row.Item as CoreTreeNode;
  332. }
  333. private CoreRow? GetRowFromIndex(int rowIndex)
  334. {
  335. return MapRow(GetNodeFromIndex(rowIndex)?.Row);
  336. }
  337. private void _tree_CellDoubleTapped(object? sender, TreeGridCellDoubleTappedEventArgs e)
  338. {
  339. _tree.Dispatcher.BeginInvoke(() =>
  340. {
  341. // This needs to happen outside the event handler, because the items source for the tree view might change during this method, and that causes an internal exception in Syncfusion. We need to finish the event before resetting the items source.
  342. Parent.DoubleClickCell(GetRowFromIndex(e.RowColumnIndex.RowIndex), GetColumn(e.RowColumnIndex.ColumnIndex));
  343. });
  344. }
  345. private void _tree_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
  346. {
  347. if (sender != _tree) return;
  348. Parent.HandleKey(e);
  349. }
  350. private void HeaderCell_LeftMouseButtonEvent(object sender, MouseButtonEventArgs e)
  351. {
  352. if (sender is not TreeGridHeaderCell header) return;
  353. var index = _tree.Columns.IndexOf(header.Column);
  354. if (GetColumn(index) is not DynamicColumnBase column)
  355. return;
  356. if(column is DynamicActionColumn dac)
  357. {
  358. Parent.ExecuteActionColumn(dac, null);
  359. }
  360. }
  361. private void _tree_CellTapped(object? sender, TreeGridCellTappedEventArgs e)
  362. {
  363. if (!_tree.IsEnabled)
  364. return;
  365. if (GetColumn(e.RowColumnIndex.ColumnIndex) is not DynamicColumnBase column)
  366. return;
  367. if(e.ChangedButton == MouseButton.Left)
  368. {
  369. if(column is DynamicActionColumn dac)
  370. {
  371. Parent.ExecuteActionColumn(dac, SelectedRows);
  372. }
  373. }
  374. else if(e.ChangedButton == MouseButton.Right)
  375. {
  376. if(column is DynamicMenuColumn dmc)
  377. {
  378. Parent.ExecuteActionColumn(dmc, null);
  379. }
  380. else
  381. {
  382. Parent.OpenColumnMenu(column);
  383. }
  384. }
  385. }
  386. #endregion
  387. #region Selection
  388. public CoreRow[] SelectedRows
  389. {
  390. get
  391. {
  392. return _tree.SelectedItems.OfType<CoreTreeNode>()
  393. .Select(x => GetRow(x)).NotNull().ToArray();
  394. }
  395. set
  396. {
  397. _tree.SelectedItems.Clear();
  398. foreach (var row in value)
  399. {
  400. _tree.SelectedItems.Add(Nodes.Find(row.Get<Guid>(IDColumn.Property)));
  401. }
  402. }
  403. }
  404. private void _tree_SelectionChanged(object? sender, GridSelectionChangedEventArgs e)
  405. {
  406. if(Parent.IsReady && !Parent.IsRefreshing)
  407. {
  408. Parent.SelectItems(SelectedRows);
  409. }
  410. }
  411. private void _tree_SelectionChanging(object? sender, GridSelectionChangingEventArgs e)
  412. {
  413. var cancel = new CancelEventArgs();
  414. Parent.BeforeSelection(cancel);
  415. if (cancel.Cancel)
  416. {
  417. e.Cancel = true;
  418. }
  419. }
  420. #endregion
  421. #region FilterUI
  422. private void _tree_FilterItemsPopulating(object? sender, Syncfusion.UI.Xaml.TreeGrid.Filtering.TreeGridFilterItemsPopulatingEventArgs e)
  423. {
  424. var colIdx = _tree.Columns.IndexOf(e.Column);
  425. var column = GetColumn(colIdx);
  426. if(column is not null)
  427. {
  428. var filterItems = Parent.GetColumnFilterItems(column);
  429. if(filterItems is not null)
  430. {
  431. e.ItemsSource = filterItems.Select(x => new FilterElement
  432. {
  433. DisplayText = x, ActualValue = x
  434. });
  435. }
  436. else if (column is DynamicActionColumn dac && dac.Filters is not null)
  437. {
  438. e.ItemsSource = dac.Filters.Select(x => new FilterElement
  439. {
  440. DisplayText = x, ActualValue = x,
  441. IsSelected = (dac.SelectedFilters is null || dac.SelectedFilters.Contains(x))
  442. && (dac.ExcludeFilters is null || dac.ExcludeFilters.Contains(x))
  443. });
  444. }
  445. else if (column is DynamicGridColumn dgc)
  446. {
  447. var preds = e.Column.FilterPredicates.Select(x => x.FilterValue).ToArray();
  448. var data = Parent.Data.Rows.Select(r => r.Get<String>(dgc.ColumnName)).OrderBy(x=>x);
  449. e.ItemsSource = data.Select(x => new FilterElement()
  450. { DisplayText = x ?? "(Blanks)", ActualValue = x, IsSelected = preds.Length == 0 || preds.Contains(x) });
  451. }
  452. }
  453. }
  454. private void _tree_FilterChanged(object? sender, Syncfusion.UI.Xaml.TreeGrid.Filtering.TreeGridFilterChangedEventArgs e)
  455. {
  456. var col = _tree.Columns.IndexOf(e.Column);
  457. if (GetColumn(col) is DynamicActionColumn column)
  458. {
  459. if (e.FilterPredicates != null)
  460. {
  461. var filter = e.FilterPredicates.Select(x => x.FilterValue.ToString()!).ToArray();
  462. var include = e.FilterPredicates.Any(x => x.FilterType == FilterType.Equals);
  463. if (include)
  464. {
  465. column.SelectedFilters = filter;
  466. column.ExcludeFilters = null;
  467. }
  468. else if(column.Filters is not null)
  469. {
  470. column.SelectedFilters = column.Filters.Except(filter).ToArray();
  471. column.ExcludeFilters = null;
  472. }
  473. else
  474. {
  475. column.SelectedFilters = null;
  476. column.ExcludeFilters = filter;
  477. }
  478. }
  479. else
  480. column.SelectedFilters = Array.Empty<string>();
  481. _tree.ClearFilter(e.Column);
  482. //e.FilterPredicates?.Clear();
  483. //e.FilterPredicates?.Add(new FilterPredicate() { PredicateType = PredicateType.Or, FilterBehavior = Syncfusion.Data.FilterBehavior.StringTyped, FilterMode = ColumnFilter.DisplayText, FilterType = Syncfusion.Data.FilterType.NotEquals, FilterValue = "" });
  484. //e.FilterPredicates?.Add(new FilterPredicate() { PredicateType = PredicateType.Or, FilterBehavior = Syncfusion.Data.FilterBehavior.StringTyped, FilterMode = ColumnFilter.DisplayText, FilterType = Syncfusion.Data.FilterType.Equals, FilterValue = "" });
  485. Parent.Refresh(false, false);
  486. }
  487. if (e.FilterPredicates == null)
  488. {
  489. if (FilterPredicates.ContainsKey(e.Column.MappingName))
  490. FilterPredicates.Remove(e.Column.MappingName);
  491. }
  492. else
  493. {
  494. FilterPredicates[e.Column.MappingName] = Serialization.Serialize(e.FilterPredicates, true);
  495. }
  496. Parent.UIFilterChanged(this);
  497. UpdateRecordCount();
  498. CalculateSummaries();
  499. }
  500. public void AddVisualFilter(string column, string value, FilterType filtertype = FilterType.Contains)
  501. {
  502. if (value.IsNullOrWhiteSpace())
  503. return;
  504. var col = _tree.Columns.FirstOrDefault((x => string.Equals(x.MappingName?.ToUpper(),column?.Replace(".", "_").ToUpper())));
  505. if (col != null)
  506. {
  507. col.FilterPredicates.Add(new FilterPredicate { FilterType = filtertype, FilterValue = value });
  508. }
  509. }
  510. public List<Tuple<string, Func<CoreRow, bool>>> GetFilterPredicates()
  511. {
  512. var list = new List<Tuple<string, Func<CoreRow, bool>>>();
  513. foreach (var column in _tree.Columns)
  514. {
  515. var colIndex = _tree.Columns.IndexOf(column);
  516. var col = ColumnList[colIndex];
  517. if (col is DynamicGridColumn gridColumn)
  518. {
  519. var rowPredicate = DynamicGridGridUIComponentExtension.ConvertColumnPredicates(gridColumn, column.FilterPredicates);
  520. if(rowPredicate is not null)
  521. {
  522. list.Add(new(gridColumn.ColumnName, rowPredicate));
  523. }
  524. }
  525. else if(col is DynamicActionColumn dac && dac.FilterRecord is not null)
  526. {
  527. if(dac.SelectedFilters is not null && dac.SelectedFilters.Length > 0)
  528. {
  529. list.Add(new(column.MappingName, (row) => dac.FilterRecord(row, dac.SelectedFilters)));
  530. }
  531. if(dac.ExcludeFilters is not null && dac.ExcludeFilters.Length > 0)
  532. {
  533. list.Add(new(column.MappingName, (row) => !dac.FilterRecord(row, dac.ExcludeFilters)));
  534. }
  535. }
  536. }
  537. return list;
  538. }
  539. #endregion
  540. private void ColumnsMenu_ContextMenuOpening(object sender, RoutedEventArgs e)
  541. {
  542. if (sender is not ContextMenu menu) return;
  543. menu.Items.Clear();
  544. Parent.LoadColumnsMenu(menu);
  545. }
  546. public bool OptionsChanged()
  547. {
  548. ColumnsMenu.Visibility = Parent.Options.SelectColumns ? Visibility.Visible : Visibility.Hidden;
  549. var allowEditing = Parent.IsDirectEditMode();
  550. var reloadColumns = false;
  551. if (_tree.AllowEditing != allowEditing)
  552. {
  553. _tree.NavigationMode = allowEditing ? NavigationMode.Cell : NavigationMode.Row;
  554. _tree.AllowEditing = allowEditing;
  555. reloadColumns = true;
  556. }
  557. _tree.AllowFiltering = Parent.Options.FilterRows;
  558. if (Parent.Options.DragSource)
  559. {
  560. if (!_tree.AllowDraggingRows)
  561. {
  562. _tree.AllowDraggingRows = true;
  563. _tree.RowDragDropController.DragStart += RowDragDropController_DragStart;
  564. }
  565. }
  566. else
  567. {
  568. if (_tree.AllowDraggingRows)
  569. {
  570. _tree.AllowDraggingRows = false;
  571. _tree.RowDragDropController.DragStart -= RowDragDropController_DragStart;
  572. }
  573. }
  574. _tree.AllowDrop = Parent.Options.DragTarget;
  575. _tree.SelectionMode = Parent.Options.MultiSelect ? GridSelectionMode.Extended : GridSelectionMode.Single;
  576. return reloadColumns;
  577. }
  578. private void _tree_CellToolTipOpening(object? sender, TreeGridCellToolTipOpeningEventArgs e)
  579. {
  580. if (GetColumn(e.RowColumnIndex.ColumnIndex) is not DynamicActionColumn col)
  581. return;
  582. var toolTip = col.ToolTip;
  583. if (toolTip is null)
  584. return;
  585. var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
  586. e.ToolTip.Template = TemplateGenerator.CreateControlTemplate(
  587. typeof(ToolTip),
  588. () => toolTip.Invoke(col, row)
  589. );
  590. }
  591. #region Styles
  592. protected virtual Brush? GetCellBackground(CoreRow row, DynamicColumnBase column) => null;
  593. protected virtual Brush? GetCellForeground(CoreRow row, DynamicColumnBase column) => null;
  594. protected virtual double? GetCellFontSize(CoreRow row, DynamicColumnBase column) => null;
  595. protected virtual FontStyle? GetCellFontStyle(CoreRow row, DynamicColumnBase column) => null;
  596. protected virtual FontWeight? GetCellFontWeight(CoreRow row, DynamicColumnBase column) => null;
  597. protected virtual Brush? GetCellSelectionForegroundBrush() => DynamicGridUtils.SelectionForeground;
  598. protected virtual Brush? GetCellSelectionBackgroundBrush() => DynamicGridUtils.SelectionBackground;
  599. protected virtual Style GetHeaderCellStyle(DynamicColumnBase column)
  600. {
  601. var headStyle = new Style(typeof(TreeGridHeaderCell));
  602. headStyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
  603. headStyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
  604. headStyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
  605. if(column is DynamicActionColumn actionColumn)
  606. {
  607. headStyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0)));
  608. headStyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
  609. if(column is DynamicImageColumn imgCol)
  610. {
  611. if (imgCol.HeaderText.IsNullOrWhiteSpace())
  612. {
  613. var image = imgCol.Image?.Invoke(null);
  614. if (image != null)
  615. {
  616. var template = new ControlTemplate(typeof(GridHeaderCellControl));
  617. var border = new FrameworkElementFactory(typeof(Border));
  618. border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro));
  619. border.SetValue(Border.PaddingProperty, new Thickness(4));
  620. var img = new FrameworkElementFactory(typeof(Image));
  621. img.SetValue(Image.SourceProperty, image);
  622. border.AppendChild(img);
  623. template.VisualTree = border;
  624. headStyle.Setters.Add(new Setter(Control.TemplateProperty, template));
  625. }
  626. }
  627. }
  628. if (actionColumn.VerticalHeader && !actionColumn.HeaderText.IsNullOrWhiteSpace())
  629. {
  630. headStyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Left));
  631. headStyle.Setters.Add(new Setter(Control.TemplateProperty,
  632. Application.Current.Resources["VerticalColumnHeader"] as ControlTemplate));
  633. }
  634. }
  635. return headStyle;
  636. }
  637. protected virtual Style GetSummaryCellStyle(DynamicColumnBase column)
  638. {
  639. var style = new Style(typeof(SummaryCellControl));
  640. style.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
  641. style.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
  642. if(column is DynamicGridColumn gridColumn)
  643. {
  644. style.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty,
  645. column != null ? gridColumn.HorizontalAlignment(typeof(double)) : HorizontalAlignment.Right));
  646. }
  647. else
  648. {
  649. style.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Right));
  650. }
  651. style.Setters.Add(new Setter(Control.VerticalContentAlignmentProperty, VerticalAlignment.Center));
  652. style.Setters.Add(new Setter(Control.BorderBrushProperty, new SolidColorBrush(Colors.Gray)));
  653. style.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0, 0.75, 0.75, 0.0)));
  654. style.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
  655. style.Setters.Add(new Setter(Control.FontWeightProperty, FontWeights.DemiBold));
  656. style.Setters.Add(new Setter(Control.PaddingProperty, new Thickness(4)));
  657. return style;
  658. }
  659. #endregion
  660. #region Sizing
  661. public double RowHeight
  662. {
  663. get => _tree.RowHeight;
  664. set => _tree.RowHeight = value;
  665. }
  666. public double HeaderRowHeight
  667. {
  668. get => _tree.HeaderRowHeight;
  669. set => _tree.HeaderRowHeight = value;
  670. }
  671. private void _tree_SizeChanged(object sender, SizeChangedEventArgs e)
  672. {
  673. CalculateRowHeight();
  674. if (Parent.IsReady && !Parent.IsRefreshing)
  675. ResizeColumns(_tree, e.NewSize.Width - 2, e.NewSize.Height - 2);
  676. }
  677. int IDynamicGridUIComponent<T>.DesiredWidth()
  678. {
  679. return this.DesiredWidth();
  680. }
  681. #endregion
  682. #region Context Menu
  683. private void _tree_ContextMenuOpening(object sender, ContextMenuEventArgs e)
  684. {
  685. _menu.Items.Clear();
  686. if (OnContextMenuOpening is not null)
  687. {
  688. OnContextMenuOpening.Invoke((_tree.SelectedItem as CoreTreeNode)!, _menu);
  689. if(_menu.Items.Count == 0)
  690. {
  691. e.Handled = true;
  692. }
  693. }
  694. else
  695. {
  696. if (Parent.Options.AddRows)
  697. {
  698. _menu.AddItem("Add Item", null, (_tree.SelectedItem as CoreTreeNode)!.ID, (id) => DoAddItem(id, true));
  699. }
  700. }
  701. }
  702. #endregion
  703. #region CRUD
  704. protected T DoCreateItem(Guid parent)
  705. {
  706. var result = Parent.CreateItem();
  707. CoreUtils.SetPropertyValue(result, ParentColumn.Property, parent);
  708. return result;
  709. }
  710. protected void DoAddItem(Guid id, bool edit)
  711. {
  712. try
  713. {
  714. var item = DoCreateItem(id);
  715. if (edit)
  716. {
  717. if (Parent.EditItems(new[] { item }))
  718. {
  719. Parent.DoChanged();
  720. Parent.Refresh(false, true);
  721. }
  722. }
  723. else
  724. {
  725. Parent.SaveItem(item);
  726. Parent.DoChanged();
  727. Parent.Refresh(false, true);
  728. }
  729. }
  730. catch (Exception e)
  731. {
  732. MessageWindow.ShowError("An error occurred while adding an item", e);
  733. }
  734. }
  735. #endregion
  736. #region Rows
  737. private CoreRow? GetRow(CoreTreeNode? node)
  738. {
  739. return MapRow(node?.Row);
  740. }
  741. private CoreRow? MapRow(CoreRow? row)
  742. {
  743. if (row is null) return null;
  744. var index = row.Index;
  745. if (index < 0 || index >= Parent.Data.Rows.Count) return null;
  746. return Parent.Data.Rows[row.Index];
  747. }
  748. private CoreTreeNode? GetNode(CoreRow row)
  749. {
  750. if (_innerTable is null || row.Index < 0 || row.Index >= _innerTable.Rows.Count) return null;
  751. var _innerRow = _innerTable.Rows[row.Index];
  752. var node = Nodes.Find(_innerRow);
  753. return node;
  754. }
  755. public CoreRow[] GetVisibleRows()
  756. {
  757. return _tree.View?.Nodes.Select(x => MapRow((x.Item as CoreTreeNode)?.Row)).NotNull().ToArray() ?? new CoreRow[] { };
  758. }
  759. #endregion
  760. #region Columns
  761. private class StackedHeaderRenderer : TreeGridStackedHeaderCellRenderer
  762. {
  763. private Style Style;
  764. public StackedHeaderRenderer()
  765. {
  766. var headstyle = new Style(typeof(TreeGridStackedHeaderCell));
  767. headstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
  768. headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
  769. headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
  770. headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0, 0.0, 0, 0)));
  771. headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
  772. Style = headstyle;
  773. }
  774. public override void OnInitializeEditElement(TreeDataColumnBase dataColumn, TreeGridStackedHeaderCell uiElement, object dataContext)
  775. {
  776. uiElement.Style = Style;
  777. base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
  778. }
  779. }
  780. private readonly List<DynamicColumnBase> ColumnList = new();
  781. private List<DynamicActionColumn> ActionColumns = new();
  782. private List<Summary> Summaries = new();
  783. private readonly Dictionary<string, string> FilterPredicates = new();
  784. private DynamicColumnBase? GetColumn(int index) =>
  785. index >= 0 && index < ColumnList.Count ? ColumnList[index] : null;
  786. private void ApplyFilterStyle(TreeGridColumn column, bool filtering, bool isactioncolumn)
  787. {
  788. var filterstyle = new Style();
  789. if (filtering)
  790. {
  791. filterstyle.Setters.Add(new Setter(Control.BackgroundProperty, DynamicGridUtils.FilterBackground));
  792. column.ImmediateUpdateColumnFilter = true;
  793. column.ColumnFilter = ColumnFilter.DisplayText;
  794. column.AllowBlankFilters = true;
  795. column.AllowSorting = isactioncolumn
  796. ? false
  797. : Parent.CanSort();
  798. }
  799. else
  800. {
  801. filterstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
  802. filterstyle.Setters.Add(new Setter(Control.IsEnabledProperty, false));
  803. column.ColumnFilter = ColumnFilter.Value;
  804. column.AllowFiltering = false;
  805. column.AllowSorting = false;
  806. }
  807. }
  808. public class TemplateColumnSelector(DynamicGridTreeUIComponent<T> parent, Func<CoreRow, FrameworkElement?> dataTemplate) : DataTemplateSelector
  809. {
  810. public Func<CoreRow, FrameworkElement?> DataTemplate { get; init; } = dataTemplate;
  811. public DynamicGridTreeUIComponent<T> Parent { get; init; } = parent;
  812. public override DataTemplate? SelectTemplate(object item, DependencyObject container)
  813. {
  814. if (item is not CoreTreeNode node) return null;
  815. var row = Parent.MapRow(node.Row);
  816. if (row is null) return null;
  817. return TemplateGenerator.CreateDataTemplate(() =>
  818. {
  819. return DataTemplate(row);
  820. });
  821. }
  822. }
  823. private void LoadActionColumns(DynamicActionColumnPosition position)
  824. {
  825. for (var i = 0; i < ActionColumns.Count; i++)
  826. {
  827. var column = ActionColumns[i];
  828. if (column.Position == position)
  829. {
  830. var sColName = $"[_ActionColumn{i}]";
  831. var summary = column.Summary();
  832. if(summary is not null)
  833. {
  834. Summaries.Add(new(column, summary, null, null));
  835. }
  836. if (column is DynamicImageColumn imgcol)
  837. {
  838. var newcol = new TreeGridTemplateColumn();
  839. newcol.CellTemplateSelector = new TemplateColumnSelector(this, row =>
  840. {
  841. var image = new Image
  842. {
  843. Width = _tree.RowHeight - 8,
  844. Height = _tree.RowHeight - 8,
  845. };
  846. image.SetBinding(Image.SourceProperty, new Binding(sColName));
  847. return image;
  848. });
  849. newcol.AllowEditing = false;
  850. newcol.UpdateTrigger = UpdateSourceTrigger.PropertyChanged;
  851. newcol.Width = column.Width == 0 ? _tree.RowHeight : column.Width;
  852. newcol.Padding = new Thickness(4);
  853. newcol.ColumnSizer = TreeColumnSizer.None;
  854. newcol.HeaderText = column.HeaderText;
  855. newcol.MappingName = sColName;
  856. ApplyFilterStyle(newcol, false, true);
  857. newcol.ShowToolTip = column.ToolTip != null;
  858. newcol.ShowHeaderToolTip = column.ToolTip != null;
  859. var headstyle = GetHeaderCellStyle(column);
  860. headstyle.Setters.Add(new EventSetter(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderCell_LeftMouseButtonEvent)));
  861. newcol.HeaderStyle = GetHeaderCellStyle(column);
  862. _tree.Columns.Add(newcol);
  863. ColumnList.Add(column);
  864. }
  865. else if (column is DynamicTextColumn txtCol)
  866. {
  867. var newcol = new TreeGridTextColumn();
  868. newcol.TextWrapping = TextWrapping.NoWrap;
  869. newcol.TextAlignment = txtCol.Alignment == Alignment.NotSet
  870. ? TextAlignment.Left
  871. : txtCol.Alignment == Alignment.BottomLeft || txtCol.Alignment == Alignment.MiddleLeft ||
  872. txtCol.Alignment == Alignment.TopLeft
  873. ? TextAlignment.Left
  874. : txtCol.Alignment == Alignment.BottomCenter || txtCol.Alignment == Alignment.MiddleCenter ||
  875. txtCol.Alignment == Alignment.TopCenter
  876. ? TextAlignment.Center
  877. : TextAlignment.Right;
  878. newcol.AllowEditing = false;
  879. newcol.UpdateTrigger = UpdateSourceTrigger.PropertyChanged;
  880. newcol.MappingName = sColName;
  881. newcol.Width = column.Width;
  882. newcol.ColumnSizer = TreeColumnSizer.None;
  883. newcol.HeaderText = column.HeaderText;
  884. //newcol.AllowFiltering = column.Filters != null && column.Filters.Any();
  885. newcol.AllowSorting = false;
  886. newcol.ShowHeaderToolTip = column.ToolTip != null;
  887. ApplyFilterStyle(newcol, false, true);
  888. var headstyle = GetHeaderCellStyle(column);
  889. headstyle.Setters.Add(new EventSetter(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderCell_LeftMouseButtonEvent)));
  890. newcol.HeaderStyle = headstyle;
  891. _tree.Columns.Add(newcol);
  892. ColumnList.Add(column);
  893. }
  894. else if (column is DynamicTemplateColumn tmplCol)
  895. {
  896. var newcol = new TreeGridTemplateColumn();
  897. newcol.CellTemplateSelector = new TemplateColumnSelector(this, tmplCol.Template);
  898. newcol.AllowEditing = false;
  899. newcol.UpdateTrigger = UpdateSourceTrigger.PropertyChanged;
  900. newcol.Width = tmplCol.Width;
  901. newcol.ColumnSizer = TreeColumnSizer.None;
  902. newcol.HeaderText = column.HeaderText;
  903. //newcol.AllowFiltering = false;
  904. newcol.AllowSorting = false;
  905. newcol.ShowToolTip = false;
  906. newcol.ShowHeaderToolTip = false;
  907. newcol.MappingName = sColName;
  908. ApplyFilterStyle(newcol, false, true);
  909. var headstyle = GetHeaderCellStyle(column);
  910. headstyle.Setters.Add(new EventSetter(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderCell_LeftMouseButtonEvent)));
  911. newcol.HeaderStyle = headstyle;
  912. _tree.Columns.Add(newcol);
  913. ColumnList.Add(column);
  914. }
  915. }
  916. }
  917. }
  918. private void LoadDataColumns(DynamicGridColumns columns)
  919. {
  920. foreach (var column in columns)
  921. {
  922. if(this.CreateEditorColumn(column, out var newcol, out var prop))
  923. {
  924. newcol.GetEntity = () => _editingObject?.Object;
  925. newcol.EntityChanged += DoEntityChanged;
  926. var newColumn = newcol.CreateTreeGridColumn();
  927. var summary = newcol.Summary();
  928. if(summary is not null)
  929. {
  930. Summaries.Add(new(column, summary, null, null));
  931. }
  932. ApplyFilterStyle(newColumn, newcol.Filtered, false);
  933. newColumn.HeaderStyle = GetHeaderCellStyle(column);
  934. var cellstyle = new Style();
  935. if (Parent.IsDirectEditMode())
  936. {
  937. var editor = Parent.CustomiseEditor(column, column.Editor);
  938. if (editor is null || !editor.Editable.IsDirectEditable())
  939. {
  940. cellstyle.Setters.Add(new Setter(Control.BackgroundProperty,
  941. new SolidColorBrush(Colors.WhiteSmoke)));
  942. newColumn.AllowEditing = false;
  943. }
  944. else
  945. {
  946. cellstyle.Setters.Add(new Setter(Control.BackgroundProperty,
  947. new SolidColorBrush(Colors.LightYellow)));
  948. newColumn.AllowEditing = true;
  949. }
  950. cellstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
  951. newColumn.CellStyle = cellstyle;
  952. }
  953. else
  954. {
  955. cellstyle.Setters.Add(new Setter(Control.BackgroundProperty,
  956. new Binding()
  957. {
  958. Path = new PropertyPath("."), Converter = CellBackgroundConverter,
  959. ConverterParameter = new DynamicGridCellStyleParameters(column,DependencyProperty.UnsetValue)
  960. }));
  961. cellstyle.Setters.Add(new Setter(Control.ForegroundProperty,
  962. new Binding()
  963. {
  964. Converter = CellForegroundConverter,
  965. ConverterParameter = new DynamicGridCellStyleParameters(column,DependencyProperty.UnsetValue)
  966. }));
  967. cellstyle.Setters.Add(new Setter(Control.FontSizeProperty,
  968. new Binding()
  969. {
  970. Converter = CellFontSizeConverter,
  971. ConverterParameter = new DynamicGridCellStyleParameters(column,DependencyProperty.UnsetValue)
  972. }));
  973. cellstyle.Setters.Add(new Setter(Control.FontStyleProperty,
  974. new Binding()
  975. {
  976. Converter = CellFontStyleConverter,
  977. ConverterParameter = new DynamicGridCellStyleParameters(column,DependencyProperty.UnsetValue)
  978. }));
  979. cellstyle.Setters.Add(new Setter(Control.FontWeightProperty,
  980. new Binding()
  981. {
  982. Converter = CellFontWeightConverter,
  983. ConverterParameter = new DynamicGridCellStyleParameters(column,DependencyProperty.UnsetValue)
  984. }));
  985. newColumn.CellStyle = cellstyle;
  986. }
  987. _tree.Columns.Add(newColumn);
  988. ColumnList.Add(column);
  989. foreach (var extra in newcol.ExtraColumns)
  990. Parent.AddHiddenColumn(extra);
  991. }
  992. }
  993. }
  994. private void LoadStackedHeaders(DynamicGridColumnGroupings groupings)
  995. {
  996. _tree.StackedHeaderRows.Clear();
  997. foreach(var grouping in groupings)
  998. {
  999. var row = new StackedHeaderRow();
  1000. var i = 0;
  1001. foreach(var group in grouping.Groups)
  1002. {
  1003. var start = Math.Max(i, ColumnList.IndexOf(group.StartColumn));
  1004. var end = Math.Max(start, ColumnList.IndexOf(group.EndColumn));
  1005. if(end < start)
  1006. {
  1007. i = end + 1;
  1008. continue;
  1009. }
  1010. var cols = Enumerable.Range(start, end - start + 1).Select(i => _tree.Columns[i]).ToArray();
  1011. var stackedColumn = new StackedColumn
  1012. {
  1013. HeaderText = group.Header,
  1014. ChildColumns = string.Join(',', cols.Select(x => x.MappingName))
  1015. };
  1016. row.StackedColumns.Add(stackedColumn);
  1017. i = end + 1;
  1018. }
  1019. _tree.StackedHeaderRows.Add(row);
  1020. }
  1021. if(groupings.Count > 0)
  1022. {
  1023. _tree.CellRenderers.Remove("StackedHeader");
  1024. _tree.CellRenderers.Add("StackedHeader", new StackedHeaderRenderer());
  1025. }
  1026. }
  1027. public void RefreshColumns(DynamicGridColumns columns, DynamicActionColumns actionColumns, DynamicGridColumnGroupings groupings)
  1028. {
  1029. _tree.ItemsSource = null;
  1030. _tree.Columns.Suspend();
  1031. ColumnList.Clear();
  1032. _tree.Columns.Clear();
  1033. Summaries.Clear();
  1034. ActionColumns = actionColumns.ToList();
  1035. //_tree.Columns.Add(new TreeGridTextColumn()
  1036. // {
  1037. // MappingName = "Number",
  1038. // Width = _shownumbers ? 50 : 0,
  1039. // TextAlignment = TextAlignment.Right
  1040. // }
  1041. //);
  1042. LoadActionColumns(DynamicActionColumnPosition.Start);
  1043. LoadDataColumns(columns);
  1044. LoadActionColumns(DynamicActionColumnPosition.End);
  1045. LoadStackedHeaders(groupings);
  1046. _tree.Columns.Resume();
  1047. _tree.RefreshColumns();
  1048. foreach (var key in FilterPredicates.Keys.ToArray())
  1049. if (_tree.Columns.Any(x => string.Equals(x.MappingName, key)))
  1050. {
  1051. var predicates = Serialization.Deserialize<List<FilterPredicate>>(FilterPredicates[key]);
  1052. foreach (var predicate in predicates)
  1053. {
  1054. _tree.Columns[key].FilterPredicates.Add(predicate);
  1055. }
  1056. }
  1057. else
  1058. {
  1059. FilterPredicates.Remove(key);
  1060. }
  1061. ResizeColumns(_tree, _tree.ActualWidth - 2, _tree.ActualHeight - 2);
  1062. }
  1063. private void ResizeColumns(SfTreeGrid grid, double width, double height)
  1064. {
  1065. if (Parent.Data == null || width <= 0)
  1066. return;
  1067. grid.Dispatcher.BeginInvoke(() =>
  1068. {
  1069. foreach (var (index, size) in this.CalculateColumnSizes(width))
  1070. {
  1071. var colSize = Math.Max(0.0F, size);
  1072. _tree.Columns[index].Width = colSize;
  1073. }
  1074. RebuildSummaryRow();
  1075. });
  1076. }
  1077. #endregion
  1078. #region Summary
  1079. private class Summary(DynamicColumnBase column, IDynamicGridSummary summary, SummaryCellControl? control, object? data)
  1080. {
  1081. public DynamicColumnBase Column { get; set; } = column;
  1082. public IDynamicGridSummary SummaryDefinition { get; set; } = summary;
  1083. public SummaryCellControl? Control { get; set; } = control;
  1084. public object? Data { get; set; } = data;
  1085. }
  1086. protected class SummaryCellControl : ContentControl
  1087. {
  1088. public SummaryCellControl()
  1089. {
  1090. var template = new ControlTemplate(typeof(ContentControl));
  1091. var factory = new FrameworkElementFactory(typeof(Border));
  1092. factory.Bind<ContentControl, Brush>(Border.BorderBrushProperty, x => x.BorderBrush);
  1093. factory.Bind<ContentControl, Thickness>(Border.BorderThicknessProperty, x => x.BorderThickness);
  1094. factory.Bind<ContentControl, Brush>(Border.BackgroundProperty, x => x.Background);
  1095. factory.Bind<ContentControl, Thickness>(Border.PaddingProperty, x => x.Padding);
  1096. var content = new FrameworkElementFactory(typeof(ContentPresenter));
  1097. content.Bind<ContentControl, HorizontalAlignment>(ContentPresenter.HorizontalAlignmentProperty, x => x.HorizontalContentAlignment);
  1098. content.Bind<ContentControl, VerticalAlignment>(ContentPresenter.VerticalAlignmentProperty, x => x.VerticalContentAlignment);
  1099. factory.AppendChild(content);
  1100. template.VisualTree = factory;
  1101. Template = template;
  1102. }
  1103. }
  1104. private void RebuildSummaryRow()
  1105. {
  1106. _summaryRow.RowDefinitions.Clear();
  1107. _summaryRow.ColumnDefinitions.Clear();
  1108. _summaryRow.Children.Clear();
  1109. var row = _summaryRow.AddRow(GridUnitType.Auto);
  1110. row.MinHeight = _tree.RowHeight;
  1111. foreach(var (i, column) in _tree.Columns.WithIndex())
  1112. {
  1113. _summaryRow.AddColumn(column.ActualWidth);
  1114. var cell = new SummaryCellControl();
  1115. if(GetColumn(i) is DynamicColumnBase col)
  1116. {
  1117. cell.Style = GetSummaryCellStyle(col);
  1118. var summary = Summaries.FirstOrDefault(x => x.Column == col);
  1119. if(summary is not null)
  1120. {
  1121. cell.Content = summary.Data;
  1122. summary.Control = cell;
  1123. }
  1124. }
  1125. _summaryRow.AddChild(cell, 0, _summaryRow.ColumnDefinitions.Count - 1);
  1126. }
  1127. }
  1128. private void CalculateSummaries()
  1129. {
  1130. foreach(var column in ColumnList)
  1131. {
  1132. CalculateSummary(column);
  1133. }
  1134. }
  1135. private object? CalculateSummaryData(IDynamicGridSummary summary, DynamicColumnBase column)
  1136. {
  1137. if(summary is DynamicGridCountSummary count)
  1138. {
  1139. return string.Format("{0:N0}", _tree.View.Nodes.Count);
  1140. }
  1141. else if(summary is DynamicGridSumSummary sum)
  1142. {
  1143. if(column is DynamicGridColumn gridColumn)
  1144. {
  1145. var data = _tree.View.Nodes.Select(x => MapRow((x.Item as CoreTreeNode)?.Row)).NotNull()
  1146. .Select(x => x[gridColumn.ColumnName]);
  1147. object? result;
  1148. if(sum.AggregateType == typeof(double))
  1149. {
  1150. result = data.Sum(x => x is double d ? d : 0);
  1151. }
  1152. else if(sum.AggregateType == typeof(int))
  1153. {
  1154. result = data.Sum(x => x is int i ? i : 0);
  1155. }
  1156. else if(sum.AggregateType == typeof(TimeSpan))
  1157. {
  1158. result = data.Aggregate(TimeSpan.Zero, (cur, x) => x is TimeSpan ts ? cur + ts : cur);
  1159. }
  1160. else
  1161. {
  1162. result = null;
  1163. }
  1164. if(result is not null)
  1165. {
  1166. return string.Format($"{{0:{sum.Format}}}", result);
  1167. }
  1168. }
  1169. }
  1170. else if(summary is DynamicGridCustomSummary custom)
  1171. {
  1172. var data = _tree.View.Nodes.Select(x => MapRow((x.Item as CoreTreeNode)?.Row)).NotNull();
  1173. var result = custom.Aggregate(data);
  1174. if(result is not null)
  1175. {
  1176. return string.Format($"{{0:{custom.Format}}}", result);
  1177. }
  1178. }
  1179. else if(summary is DynamicGridTemplateSummary template)
  1180. {
  1181. return template.Template();
  1182. }
  1183. return null;
  1184. }
  1185. private void CalculateSummary(DynamicColumnBase column)
  1186. {
  1187. var (idx, summary) = Summaries.WithIndex().FirstOrDefault(x => x.Value.Column == column);
  1188. if(summary is null)
  1189. {
  1190. return;
  1191. }
  1192. var colIdx = ColumnList.IndexOf(summary.Column);
  1193. if(colIdx == -1)
  1194. {
  1195. return;
  1196. }
  1197. summary.Data = CalculateSummaryData(summary.SummaryDefinition, column);
  1198. if(summary.Control is not null)
  1199. {
  1200. summary.Control.Content = summary.Data;
  1201. }
  1202. }
  1203. #endregion
  1204. #region Refresh
  1205. public CoreTreeNodes Nodes { get; set; }
  1206. private CoreTable? _innerTable;
  1207. private bool _invalidating = false;
  1208. public void BeforeRefresh()
  1209. {
  1210. if(_summaryRow is not null)
  1211. {
  1212. _summaryRow.Visibility = Visibility.Collapsed;
  1213. }
  1214. _tree.SelectionForeground = GetCellSelectionForegroundBrush();
  1215. _tree.SelectionBackground = GetCellSelectionBackgroundBrush();
  1216. }
  1217. public void RefreshData(CoreTable data)
  1218. {
  1219. var nodes = new CoreTreeNodes();
  1220. _innerTable = new CoreTable();
  1221. _innerTable.LoadColumns(data.Columns);
  1222. for (var i = 0; i < ActionColumns.Count; i++)
  1223. {
  1224. _innerTable.Columns.Add(
  1225. new CoreColumn
  1226. {
  1227. ColumnName = $"_ActionColumn{i}",
  1228. DataType = ActionColumns[i] is DynamicImageColumn
  1229. ? typeof(BitmapImage)
  1230. : typeof(String)
  1231. });
  1232. }
  1233. foreach (var row in data.Rows)
  1234. {
  1235. var newRow = _innerTable.NewRow();
  1236. ProcessRow(newRow, row);
  1237. _innerTable.Rows.Add(newRow);
  1238. var _id = row.Get<Guid>(IDColumn.Property);
  1239. var _parent = row.Get<Guid>(ParentColumn.Property);
  1240. nodes.Add(_id, _parent, newRow);
  1241. }
  1242. nodes.ColumnChanged += Nodes_ColumnChanged;
  1243. Nodes = nodes;
  1244. _tree.ItemsSource = nodes.Nodes;
  1245. _summaryRow.Visibility = Visibility.Visible;
  1246. CalculateSummaries();
  1247. CalculateRowHeight();
  1248. ResizeColumns(_tree, _tree.ActualWidth - 1, _tree.ActualHeight);
  1249. UpdateRecordCount();
  1250. }
  1251. public void AddPage(IEnumerable<CoreRow> page)
  1252. {
  1253. if (_innerTable is null) return;
  1254. _invalidating = true;
  1255. foreach(var row in page)
  1256. {
  1257. var newRow = _innerTable.NewRow();
  1258. ProcessRow(newRow, row);
  1259. _innerTable.Rows.Add(newRow);
  1260. var _id = row.Get<Guid>(IDColumn.Property);
  1261. var _parent = row.Get<Guid>(ParentColumn.Property);
  1262. Nodes.Add(_id, _parent, newRow);
  1263. }
  1264. CalculateSummaries();
  1265. CalculateRowHeight();
  1266. UpdateRecordCount();
  1267. _invalidating = false;
  1268. }
  1269. private void ProcessRow(CoreRow innerRow, CoreRow row)
  1270. {
  1271. innerRow.LoadValues(row.Values);
  1272. for (var i = 0; i < ActionColumns.Count; i++)
  1273. {
  1274. var ac = ActionColumns[i];
  1275. innerRow[$"_ActionColumn{i}"] = ac.Data(row);
  1276. }
  1277. }
  1278. private void CalculateRowHeight()
  1279. {
  1280. if(Parent.Data != null && Parent.Data.Rows.Count > 0)
  1281. {
  1282. var contentHeight = _tree.ActualHeight - (_tree.Padding.Top + _tree.Padding.Bottom) - 2; // Two extra pixels of space
  1283. var targetHeight = contentHeight / Parent.Data.Rows.Count;
  1284. _tree.RowHeight = Math.Max(Math.Min(targetHeight, MaxRowHeight), MinRowHeight);
  1285. }
  1286. }
  1287. private void UpdateRecordCount()
  1288. {
  1289. var count = _tree.View != null ? _tree.View.Nodes.Count : Parent.Data.Rows.Count;
  1290. Parent.UpdateRecordCount(count);
  1291. }
  1292. #endregion
  1293. #region Invalidation + Updating
  1294. public void InvalidateRow(CoreRow row)
  1295. {
  1296. if (_innerTable is null || row.Index < 0 || row.Index >= _innerTable.Rows.Count) return;
  1297. _invalidating = true;
  1298. var _innerRow = _innerTable.Rows[row.Index];
  1299. ProcessRow(_innerRow, row);
  1300. var coreTreeNode = Nodes.Find(_innerRow);
  1301. coreTreeNode?.InvalidateData();
  1302. _invalidating = false;
  1303. }
  1304. public void UpdateCell(CoreRow row, string column, object? value)
  1305. {
  1306. var node = GetNode(row);
  1307. if(node is not null)
  1308. {
  1309. node[column] = value;
  1310. node.InvalidateData();
  1311. }
  1312. }
  1313. public void UpdateCell(CoreRow row, DynamicColumnBase column)
  1314. {
  1315. var node = GetNode(row);
  1316. if(node is not null)
  1317. {
  1318. if(column is DynamicGridColumn gc)
  1319. {
  1320. node[gc.ColumnName] = row[gc.ColumnName];
  1321. }
  1322. else if(column is DynamicActionColumn ac)
  1323. {
  1324. var i = ActionColumns.IndexOf(ac);
  1325. node[$"_ActionColumn{i}"] = ac.Data(row);
  1326. }
  1327. }
  1328. }
  1329. public void UpdateRow(CoreRow row, CoreTreeNode dataRow)
  1330. {
  1331. foreach(var (key, value) in row)
  1332. {
  1333. dataRow[key] = value;
  1334. }
  1335. for (var i = 0; i < ActionColumns.Count; i++)
  1336. dataRow[$"_ActionColumn{i}"] = ActionColumns[i].Data(row);
  1337. dataRow.InvalidateData();
  1338. }
  1339. public void UpdateRow(CoreRow row)
  1340. {
  1341. var dataRow = GetNode(row);
  1342. if(dataRow is not null)
  1343. {
  1344. UpdateRow(row, dataRow);
  1345. }
  1346. }
  1347. #endregion
  1348. public void ScrollIntoView(CoreRow row)
  1349. {
  1350. _tree.ScrollInView(new RowColumnIndex(row.Index + 1, 0));
  1351. }
  1352. #region Direct Edit
  1353. private void _tree_PreviewKeyUp(object sender, KeyEventArgs e)
  1354. {
  1355. if (e.Key == Key.OemPeriod)
  1356. {
  1357. if (e.OriginalSource is Syncfusion.Windows.Shared.TimeSpanEdit editor && editor.SelectionStart < 2)
  1358. {
  1359. editor.SelectionStart = 3;
  1360. }
  1361. }
  1362. else if (e.Key == Key.Tab)
  1363. {
  1364. if (Parent.IsDirectEditMode())
  1365. {
  1366. _tree.SelectionController.CurrentCellManager.EndEdit();
  1367. _tree.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));
  1368. _tree.SelectionController.CurrentCellManager.BeginEdit();
  1369. e.Handled = true;
  1370. }
  1371. }
  1372. else if(e.Key == Key.Escape)
  1373. {
  1374. if (Parent.IsDirectEditMode())
  1375. {
  1376. bChanged = false;
  1377. }
  1378. }
  1379. }
  1380. private bool bChanged;
  1381. private class DirectEditingObject
  1382. {
  1383. public T Object { get; set; }
  1384. public CoreRow Row { get; set; }
  1385. public CoreTreeNode? Node { get; set; }
  1386. public DirectEditingObject(T obj, CoreRow row, CoreTreeNode? node)
  1387. {
  1388. Object = obj;
  1389. Row = row;
  1390. Node = node;
  1391. }
  1392. }
  1393. private DirectEditingObject? _editingObject;
  1394. private DirectEditingObject EnsureEditingObject(CoreRow row)
  1395. {
  1396. _editingObject ??= new(Parent.LoadItem(row), row, GetNode(row));
  1397. return _editingObject;
  1398. }
  1399. private void DoEntityChanged(IDynamicColumnBase column, DynamicColumnEntityChangedEventArgs args)
  1400. {
  1401. if (_editingObject is null) return;
  1402. Parent.EntityChanged(_editingObject.Object, _editingObject.Row, args.ColumnName, args.Changes);
  1403. }
  1404. private void UpdateData(string column, Dictionary<CoreColumn, object?> updates)
  1405. {
  1406. if (_editingObject is null)
  1407. return;
  1408. var coreRow = _editingObject.Row;
  1409. try
  1410. {
  1411. Parent.UpdateData(_editingObject.Object, coreRow, column, updates);
  1412. }
  1413. catch(Exception e)
  1414. {
  1415. MessageWindow.ShowError($"Error saving {typeof(T)}", e);
  1416. }
  1417. }
  1418. private void UpdateData(CoreTreeNode node, int columnIndex)
  1419. {
  1420. if (GetColumn(columnIndex) is DynamicGridColumn gridcol)
  1421. {
  1422. var datacol = Parent.Data.Columns.FirstOrDefault(x => x.ColumnName.Equals(gridcol.ColumnName));
  1423. if (datacol != null)
  1424. {
  1425. var value = node?[datacol.ColumnName];
  1426. if (value is null)
  1427. value = CoreUtils.GetDefault(datacol.DataType);
  1428. else
  1429. value = CoreUtils.ChangeType(value, datacol.DataType);
  1430. UpdateData(datacol.ColumnName, new Dictionary<CoreColumn, object?>() { { datacol, value } });
  1431. }
  1432. }
  1433. }
  1434. private Dictionary<string, CoreTable> _lookups = new();
  1435. private void _tree_CurrentCellBeginEdit(object? sender, TreeGridCurrentCellBeginEditEventArgs e)
  1436. {
  1437. var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
  1438. if (row is null)
  1439. return;
  1440. EnsureEditingObject(row);
  1441. if (_tree.Columns[e.RowColumnIndex.ColumnIndex] is TreeGridComboBoxColumn column && column.ItemsSource == null)
  1442. {
  1443. var gridColumn = GetColumn(e.RowColumnIndex.ColumnIndex);
  1444. if(gridColumn is DynamicGridColumn col)
  1445. {
  1446. var property = col.ColumnName;
  1447. var prop = CoreUtils.GetProperty(typeof(T), property);
  1448. var editor = prop.GetEditor();
  1449. if (editor is ILookupEditor lookupEditor)
  1450. {
  1451. if (!_lookups.ContainsKey(property))
  1452. _lookups[property] = lookupEditor.Values(typeof(T), property);
  1453. var combo = column;
  1454. combo.ItemsSource = _lookups[property].ToDictionary(_lookups[property].Columns[0].ColumnName, "Display");
  1455. combo.SelectedValuePath = "Key";
  1456. combo.DisplayMemberPath = "Value";
  1457. }
  1458. }
  1459. }
  1460. bChanged = false;
  1461. }
  1462. private void Nodes_ColumnChanged(CoreTreeNode node, string column)
  1463. {
  1464. if (_invalidating) return;
  1465. var row = GetRow(node);
  1466. if (row is null)
  1467. return;
  1468. var data = Parent.Data;
  1469. var dataCol = Parent.Data.Columns.FirstOrDefault(x => x.ColumnName.Equals(column));
  1470. var col = ColumnList.OfType<DynamicGridColumn>()
  1471. .FirstOrDefault(x => x.ColumnName.Equals(column));
  1472. if (col is null || dataCol is null)
  1473. return;
  1474. CalculateSummary(col);
  1475. if (col is DynamicGridCheckBoxColumn<T>)
  1476. {
  1477. EnsureEditingObject(row);
  1478. if(_editingObject is not null)
  1479. {
  1480. var value = node[column];
  1481. _invalidating = true;
  1482. UpdateData(column, new Dictionary<CoreColumn, object?>() { { dataCol, value } });
  1483. _invalidating = false;
  1484. }
  1485. _editingObject = null;
  1486. }
  1487. if (_editingObject is not null)
  1488. bChanged = true;
  1489. }
  1490. private void _tree_CurrentCellDropDownSelectionChanged(object? sender, CurrentCellDropDownSelectionChangedEventArgs e)
  1491. {
  1492. var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
  1493. if (row is null)
  1494. return;
  1495. EnsureEditingObject(row);
  1496. if ((_editingObject is not null) && (e.SelectedItem is Tuple<object?, string> tuple))
  1497. {
  1498. var gridColumn = GetColumn(e.RowColumnIndex.ColumnIndex);
  1499. if (gridColumn is DynamicGridColumn col)
  1500. {
  1501. var corecol = col.ColumnName;
  1502. var updates = new Dictionary<CoreColumn, object?>();
  1503. var prefix = string.Join(".", corecol.Split(".").Reverse().Skip(1).Reverse());
  1504. var field = corecol.Split(".").Last();
  1505. var prop = CoreUtils.GetProperty(typeof(T), corecol);
  1506. if (prop.GetEditor() is ILookupEditor editor)
  1507. {
  1508. var data = editor.Values(typeof(T), corecol);
  1509. var lookuprow = data.Rows.FirstOrDefault(r => Equals(r[field], tuple.Item1))
  1510. ?? data.NewRow(true);
  1511. foreach (CoreColumn lookupcol in data.Columns)
  1512. {
  1513. var columnname = String.IsNullOrWhiteSpace(prefix)
  1514. ? lookupcol.ColumnName
  1515. : String.Join(".", prefix, lookupcol.ColumnName);
  1516. var updatecol = Parent.Data.Columns.FirstOrDefault(x => String.Equals(x.ColumnName, columnname));
  1517. if (updatecol != null)
  1518. updates[updatecol] = lookuprow[lookupcol.ColumnName];
  1519. }
  1520. UpdateData(corecol, updates);
  1521. bChanged = true;
  1522. }
  1523. }
  1524. }
  1525. }
  1526. private void CancelEdit()
  1527. {
  1528. var obj = _editingObject;
  1529. bChanged = false;
  1530. _editingObject = null;
  1531. _tree.SelectionController.CurrentCellManager.EndEdit(false);
  1532. if(obj is not null)
  1533. {
  1534. UpdateRow(obj.Row, obj.Node);
  1535. }
  1536. }
  1537. private void _tree_CurrentCellEndEdit(object? sender, CurrentCellEndEditEventArgs e)
  1538. {
  1539. if (_editingObject is not null && bChanged)
  1540. {
  1541. UpdateData(_editingObject.Node, e.RowColumnIndex.ColumnIndex);
  1542. }
  1543. if (bChanged)
  1544. Parent.DoChanged();
  1545. bChanged = false;
  1546. _editingObject = null;
  1547. }
  1548. #endregion
  1549. #region Drag + Drop
  1550. private void _tree_DragOver(object sender, DragEventArgs e)
  1551. {
  1552. Parent.DragOver(sender, e);
  1553. }
  1554. private void _tree_Drop(object sender, DragEventArgs e)
  1555. {
  1556. Parent.Drop(sender, e);
  1557. }
  1558. private void RowDragDropController_DragStart(object? sender, TreeGridRowDragStartEventArgs e)
  1559. {
  1560. var rows = e.DraggingNodes.Select(node => MapRow((node.Item as CoreTreeNode)?.Row)).NotNull().ToArray();
  1561. Parent.DragStart(sender, rows);
  1562. }
  1563. #endregion
  1564. }