Note that there are some explanatory texts on larger screens.

plurals
  1. POgive same property to all textbox controls
    primarykey
    data
    text
    <p>how to give same property to all textboxes present in the same form.</p> <pre><code> foreach (var textbox in this.Controls.OfType&lt;TextBox&gt;()) { textbox.ContextMenu = new ContextMenu(); } </code></pre> <p>The above code works only if the textboxes are not in nested format.</p> <p>In my project I have multiple tabpages in tabcontrol. so i cant implement the above code. but i can implement the below code:</p> <pre><code> foreach (TextBox textbox in this.Controls.OfType&lt;TabControl&gt;().SelectMany(tc =&gt; tc.Controls.OfType&lt;TabPage&gt;().SelectMany(page =&gt; page.Controls.OfType&lt;TextBox&gt;()))) { textbox.ContextMenu = new ContextMenu(); } foreach (var textbox in this.tabCarInsurance.Controls.OfType&lt;TextBox&gt;()) { textbox.ContextMenu = new ContextMenu(); } foreach (var textbox in this.tabHomeLoans.Controls.OfType&lt;TextBox&gt;()) { textbox.ContextMenu = new ContextMenu(); } foreach (var textbox in this.tabRetirement.Controls.OfType&lt;TextBox&gt;()) { textbox.ContextMenu = new ContextMenu(); } </code></pre> <p>Here I am implementing for each tabControl. which still i dont like (because I have more tab pages to take care of). Is there anyway to reduce the above code.</p> <p>I tried the below code: (<em>not working</em>)</p> <pre><code> foreach (var textbox in this.Controls.OfType&lt;TabControl&gt;().OfType&lt;TextBox&gt;()) { textbox.ContextMenu = new ContextMenu(); } </code></pre> <p>I got the above code knowledge from my <a href="https://stackoverflow.com/q/12894451/1577396">previous question</a>.</p> <p>Please Help <br>Thanks in Advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload