![]() |
|
[.NET] Resetting Controls in a Form or Groupbox - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Resetting Controls in a Form or Groupbox (/showthread.php?tid=4899547) |
Resetting Controls in a Form or Groupbox - Rhez - Jul 9, 2015 Hello HackForums Gonna share something useful (I hope so) Got tired of doing this one: TextBox1.Text = "" TextBox2.Text = "" So someone help me and give me this simple snippet. I haven't found something like this here. Code Public Sub ResetSomething(frm As Form)I hope it helps you 👍 * - +Haze - Jul 9, 2015 Code frm.Controls.OfType(Of TextBox)().ToList().ForEach(Sub(txt) txt.Text.Clear())Or Code For Each txt As TextBox In frm.Controls.OfType(Of TextBox)()* - LordCoder - Jul 9, 2015 No, it's not useful. It won't be useful for nobody. * - Rhez - Jul 9, 2015 (Jul 9, 2015 07:20 AM)LordCoder Wrote: No, it's not useful. It won't be useful for nobody. Sorry for posting shit here 😭 * - Hawk HF - Jul 9, 2015 (Jul 9, 2015 08:12 AM)Rhez Wrote: Sorry for posting shit here 😭 At the moment you're only setting the .Text property of textboxes that are directly in your form. If you have textboxes within a groupbox, this code won't work. Update your thread to include a recursive control search, meaning that it will update all controls of a certain type within the child containers as well. Then it may be helpful to some. * - Odus - Jul 9, 2015 (Jul 9, 2015 04:08 AM)+Haze Wrote: Calling ToList just to access its one liner ForEach? I don't even do this! * - +Haze - Jul 9, 2015 Lool, Well Haze does that :) Edit: What should I do instead? Cast? * - Odus - Jul 9, 2015 (Jul 9, 2015 09:43 AM)+Haze Wrote: Edit: What should I do instead? Cast? I.. Oh boy. Leave it be. Your 2nd suggestion was perfectly fine. * - Nikey646 - Jul 9, 2015 (Jul 9, 2015 09:43 AM)+Haze Wrote: Lool, Well Haze does that :)Couldn't you do something along the lines of Code frm.Controls.OfType<TextBox>.Select(txt => txt.Text.Clear());Edit: Nope nope nope, that won't work, Select is the wrong Linq statement what was it damnit... * - +Haze - Jul 9, 2015 (Jul 9, 2015 11:21 AM)Nikey646 Wrote: Couldn't you do something along the lines of Finally you've upgraded to leet... what took you so long Nikey. And ask Odus, he's a Linq Guru * - Only3 - Jul 9, 2015 Array.ForEach(Me.Controls.OfType(Of TextBox).ToArray, Sub(t) t.Clear()) or Array.ForEach(Me.Controls.Cast(Of TextBox).ToArray, Sub(t) t.Clear()) * - Nikey646 - Jul 9, 2015 (Jul 9, 2015 11:30 AM)+Haze Wrote: Finally you've upgraded to leet... what took you so long Nikey. And ask Odus, he's a Linq GuruI've been leet for +1 month. I recall there being a Linq statement that allows you to modify the source...but cannot remember damnit! Atlas, i cannot find it and maybe of been thinking of Select, which is ultimately useless. My bad~ |