internal static bool SetValue(object data, string propertyName, object value) { if (DynamicHelper.CheckIsDynamicObject(data.GetType())) { return(new DynamicHelper().SetValue(data, propertyName, value)); //return DynamicPropertiesProvider.SetDynamicValue(data, propertyName, value); } else { #if WPF PropertyDescriptorCollection descriptor = TypeDescriptor.GetProperties(data.GetType()); #else PropertyInfoCollection descriptor = new PropertyInfoCollection(data.GetType()); #endif return(descriptor.SetValue(data, value, propertyName)); } }
public static bool GetIsDynamicBound(this IEnumerable collection) { var enumerator = collection.GetEnumerator(); if (!enumerator.MoveNext()) { return(false); } var record = enumerator.Current; if (record != null) { var isDynamicBound = DynamicHelper.CheckIsDynamicObject(record.GetType()); return(isDynamicBound); } return(false); }
/// <summary> /// Process drop operations in nested view. /// </summary> /// <param name="rowColumnIndex">dropped row column index.</param> /// <param name="dropPosition">drop position.</param> /// <param name="nodes">the dragging nodes which needs to be dropped.</param> /// <param name="sourceTreeGrid">the grid from which drag operation in initiated.</param> protected virtual void ProcessDropOnNestedView(RowColumnIndex rowColumnIndex, DropPosition dropPosition, ObservableCollection <TreeNode> nodes, SfTreeGrid sourceTreeGrid) { var isSameGrid = (TreeGrid == sourceTreeGrid); var treeNode = this.TreeGrid.GetNodeAtRowIndex(rowColumnIndex.RowIndex); if (treeNode == null) { return; } var data = treeNode.Item; TreeGrid.View.Suspend(); TreeGrid.SelectionController.SuspendUpdates(); ProcessDragSourceOnDrop(sourceTreeGrid, nodes); var itemIndex = -1; var nodeIndex = -1; TreeNode parentNode = null; if (dropPosition == DropPosition.DropBelow || dropPosition == DropPosition.DropAbove) { parentNode = treeNode.ParentNode; } else if (dropPosition == DropPosition.DropAsChild) { if (!treeNode.IsExpanded) { TreeGrid.ExpandNode(treeNode); } parentNode = treeNode; } IList sourceCollection = null; if (dropPosition == DropPosition.DropBelow || dropPosition == DropPosition.DropAbove) { if (treeNode.ParentNode != null) { var collection = TreeGrid.View.propertyAccessProvider.GetValue(treeNode.ParentNode.Item, TreeGrid.ChildPropertyName) as IEnumerable; sourceCollection = TreeGridHelper.GetSourceListCollection(collection); } else { sourceCollection = TreeGridHelper.GetSourceListCollection(TreeGrid.View.SourceCollection); } itemIndex = sourceCollection.IndexOf(data); if (parentNode != null) { nodeIndex = parentNode.ChildNodes.IndexOf(treeNode); } else { nodeIndex = this.TreeGrid.View.Nodes.RootNodes.IndexOf(treeNode); } if (dropPosition == DropPosition.DropBelow) { itemIndex += 1; nodeIndex += 1; } } else if (dropPosition == DropPosition.DropAsChild) { var item = treeNode.Item; var collection = TreeGrid.View.propertyAccessProvider.GetValue(item, TreeGrid.ChildPropertyName) as IEnumerable; sourceCollection = TreeGridHelper.GetSourceListCollection(collection); if (sourceCollection == null) { // Create sourcecollection by getting item type. if (!DynamicHelper.CheckIsDynamicObject(item.GetType())) { var list = item.GetType().GetProperty(TreeGrid.ChildPropertyName).PropertyType.CreateNew() as IList; if (list != null) { TreeGrid.View.propertyAccessProvider.SetValue(treeNode.Item, TreeGrid.ChildPropertyName, list); sourceCollection = list; } } else { // If item is dynamic collection, customer needs to override and add record. this.TreeGrid.View.Resume(); TreeGrid.SelectionController.ResumeUpdates(); (TreeGrid.SelectionController as TreeGridRowSelectionController).RefreshSelection(); return; } } itemIndex = sourceCollection.Count; nodeIndex = parentNode.ChildNodes.Count; } foreach (var node in nodes) { sourceCollection.Insert(itemIndex, node.Item); this.TreeGrid.View.AddNode(parentNode, node, nodeIndex, itemIndex, false); } UpdateParentNodeExpanderCell(parentNode); this.TreeGrid.View.Resume(); TreeGrid.SelectionController.ResumeUpdates(); (TreeGrid.SelectionController as TreeGridRowSelectionController).RefreshSelection(); }