void ExpandOrCollpase(object item, DataGridContext context, bool IsExpand) { if (item == null || context == null) { return; } if (!context.AreDetailsExpanded(item) && IsExpand) { context.ExpandDetails(item); } else if (!IsExpand) { context.CollapseDetails(item); return; } else { return; } var itemType = item.GetType(); // перебираем все дочерние ветки foreach (var detail in context.DetailConfigurations) { var childContext = context.GetChildContext(item, detail.RelationName); // смотрим, не пустая ли ветка if ((childContext != null) && (childContext.Items.Count > 0) && (detail.Visible)) { var propertyInfo = itemType.GetProperty(detail.RelationName); var childrenItems = propertyInfo.GetValue(item, null) as IEnumerable; if (childrenItems != null) { foreach (var childrenItem in childrenItems) { // строим дочернюю ветку со смещением первого столбца на 1 вправо ExpandOrCollpase(childrenItem, childContext, IsExpand); } } } } }