Wednesday, 28 October 2015

TreeView Traversing in c#

To get tree view structure in C# language according to business logic

private List<string> GetAllSubItems(string ItemId)
 {
    List<string> ItemIds = new List<string>();
    List<ClassName> subItems = null;
    var objController = new StorageManager();
    subItems = objController.GetAllItemPreAssemblyPickupLocationItem();
    System.Func<stringIEnumerable<ClassName>, 
                IEnumerable<ClassName>> getItems = null;
    getItems = (strItemId, Items) => Items
.Where(x => x.ItemId == strItemId).
    SelectMany(x => getItems(x.SubItemId, Items)
.Concat(new ClassName[] { x }));
    var allItems = getItems(ItemId, subItems);
    if (allItems != null && allItems.Count() > 0)
        allItems.ToList().ForEach(x => { ItemIds.Add(x.ItemId);
 ItemIds.Add(x.SubItemId); });
    return ItemIds.Distinct().ToList();
 
}

No comments:

Post a Comment