Simple Just think that you have a list in the next array
List<KeyValuePair<int, int>> groups = new List<KeyValuePair<int, int>>(); groups.Add(new KeyValuePair<int, int>(27, 1888)); groups.Add(new KeyValuePair<int, int>(1888, 5943)); groups.Add(new KeyValuePair<int, int>(1888, 5944)); groups.Add(new KeyValuePair<int, int>(5943, 2064)); groups.Add(new KeyValuePair<int, int>(5943, 2065)); groups.Add(new KeyValuePair<int, int>(5943, 2066)); groups.Add(new KeyValuePair<int, int>(5943, 2067)); groups.Add(new KeyValuePair<int, int>(2064, 6248)); groups.Add(new KeyValuePair<int, int>(2064, 6249)); groups.Add(new KeyValuePair<int, int>(2064, 6250)); groups.Add(new KeyValuePair<int, int>(2000, 1000));
To obtain dynamic data, you need to use the "Recursive Function" function. Just call the following method to get all the children of the parent
public List<int> GetAllChild(int id,List<KeyValuePair<int, int>> newLst) { List<int> list = new List<int>(); for (int i = 0; i < newLst.Count; i++) { if (Convert.ToInt32(newLst[i].Key) == id) { if (!list.Contains(Convert.ToInt32(newLst[i].Value))) { list.Add(Convert.ToInt32(newLst[i].Value)); List<int> l = GetAllChild(newLst[i].Value, newLst); list.AddRange(l); } } } return list; }
source share