I need to check all TabPages in TabControl, and if none of them have been found with certain text, then perform on a specific action.

I tried this:

foreach (TabPage item in editorTabControl.TabPages) { if (item.Text != filesList.SelectedItems[0].Text) { } } 

And the condition is fulfilled at the first village.

  • I use WinForms, I need to sort out the tabs and check the text in their headers. - MagicFun
  • Edited the question - MagicFun
  • So far, everything is logical. The condition stands on the inequality . I doubt that the text of the first tab in the collection coincides with the selected one. - rdorn
  • What do you want in the end? - rdorn
  • It is necessary to check whether there is a TabPage with a certain text, for example "test" and if it exists, then do nothing, and if not, then perform another action. I just can't figure out how to implement the condition. - MagicFun

1 answer 1

You can use the LiNQ methods:

 if (editorTabControl.TabPages.Cast<TabPage>().Any(p => p.Name == filesList.SelectedItems[0].Text) { //для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π° Π°ΠΊΡ‚ΠΈΠ²ΠΈΡ€ΡƒΠ΅ΠΌ Π²ΠΊΠ»Π°Π΄ΠΊΡƒ ΠΏΠΎ ΠΈΠΌΠ΅Π½ΠΈ editorTabControl.SelectTab(filesList.SelectedItems[0].Text); } 

Cast<T>() in this case must be called to bring the specialized collection to a generalized enumeration.