Hi David, What do you mean by incredibly slow? How many buttons are we talking about?
I just did a test with 1000 buttons and it took 3.47 milliseconds. With 5000 buttons it was 16.78 milliseconds. Did I miss something? Cheers. James. -----Original Message----- From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of David Richards Sent: Tuesday, 26 July 2011 15:46 To: ozDotNet Subject: Re: Set property of texbox by name James, This may work but it would be incredibly slow. Better to use a reference to access the control you want directly. eg something like either Ben's or my previous post. David "If we can hit that bullseye, the rest of the dominoes will fall like a house of cards... checkmate!" -Zapp Brannigan, Futurama On Tue, Jul 26, 2011 at 16:07, James Chapman-Smith <ja...@chapman-smith.com> wrote: > I assume you wanted VB.NET. If not, I can provide a better answer in C# if > you need it. > > > > Try this: > > > > For Each button In (From x In Me.GetAllControls(Me).OfType(Of > Button)() _ > > Where x.Name = "Button" & n _ > > Select x) > > button.Text = t > > Next > > > > You need to define this function: > > > > Private Function GetAllControls(ByVal control As Control) As > IEnumerable(Of Control) > > Dim r = New List(Of Control) > > r.Add(control) > > For Each c In control.Controls > > r.AddRange(GetAllControls(c)) > > Next > > Return r > > End Function > > >