private IEnumerable GetChildSourceFromParentID(object parentID, object parentItem, bool addChildNode = true) { List <object> childSource = new List <object>(); var itemsSource = (IEnumerable)this.TreeGrid.ItemsSource; var itemsCount = SourceCollection.AsQueryable().Count(); if (SelfRelationRootValue == DependencyProperty.UnsetValue && parentItem == null) { foreach (object item in itemsSource) { object childValue = propertyAccessProvider.GetValue(item, childPropertyName); int i = 0; foreach (object record in itemsSource) { object parentValue = propertyAccessProvider.GetValue(record, parentPropertyName); if (!item.Equals(record) && ((parentValue != null && parentValue.Equals(childValue)) || parentValue == childValue)) { break; } i++; if (i == itemsCount) { childSource.Add(item); } } } return(childSource as IEnumerable); } foreach (object record in itemsSource) { object childValue = propertyAccessProvider.GetValue(record, childPropertyName); if (IsEqual(parentID, childValue, parentItem == null) && record != parentItem) { if (!Nodes.RootNodes.sourceList.Contains(record)) { childSource.Add(record); } } if (!addChildNode && childSource.Count > 0) { if (CanFilter) { if (FilterItem(childSource.LastOrDefault())) { break; } } else { break; } } } return(childSource as IEnumerable); }