Search code examples
winformslinqtelerikribbon

find child control by linq


this is the code to find ribbon control

bool found = testRibbon.CommandTabs.Cast<RibbonTab>().Any(t => t.name == tab.Name);

now how can i find by name a RadRibbonBarGroup that is member of RibbonTab

The scenario is like this: I have a ribbon control and i populate the tabs from modules inside tabs i add RadRibbonBarGroup and inside RadRibbonBarGroup i add RibbonButtons now to prevent duplicates i need to check if the tab exists and the ribonbargroup exist and has the button skip that tab and bargroup else add the button.. same should be for the tabs and bargroups. That is the fastest way to achive this scenario Can i do it via linq or should i iterate with for each witch is the best solution.


Solution

  • testRibbon.CommandTabs.Cast<RibbonTab>().Where(t => t.name == tab.Name)
                          .SelectMany(x => x.Groups.Where(g => g.Name == groupName));