开发者

find control by name with linq

Hello folks is it possible to find a controll by its name via Linq?

I can iterate thorught contorl collection via for each

foreach (RibbonTab t in testRibbon.CommandTabs)
                    {
                        if (t.Name == tab.Name)
                        {
                            blnFound= true;

                        }
         开发者_如何学JAVA           }

The idea is to save memory. I create telerik ribbon tabs dynamically and i want to see if the tab is there then don't create it also i want to check the ribbonbar if it has specific RadRibbonBarGroup and RadButtonElement by name same as for ribbontab so i dont make duplicates.

Sorry if i complicated a bit.


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


Yes, this is possible with Linq-to-WindowsForms. See the following article:

http://www.codeproject.com/KB/linq/LinqToTree.aspx#linqforms

You can find all the controls with a given name like so:

var namedControls= this.Descendants()
                       .Where(ctrl => ctrl.Name="NameToFind");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜