Marc,
The recursive find control is probably the "easiest" method to use. However
it is causing performance problems, I would consider using a HashTable to
map control names to controls.
You could either populate the HashTable when you add the controls possibly
by handling the ControlAdded & ControlRemoved events (which may be difficult
if you have controls nested within controls). Note ControlAdded &
ControlRemoved are very advanced events & are normally hidden.
Or if you could simply call a recursive routine, similar to your
FindControl, that populates the hashtable when you know that all controls
have added. Such as the end of the Form.Load event or after you call a
routine that adds a number of dynamic controls...
http://msdn.microsoft.com/library/de...addedtopic.asp http://msdn.microsoft.com/library/de...movedtopic.asp
Hope this helps
Jay
"Marc Robitaille" <ma*************@ars-solutions.caa> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
| Hello,
|
| Is there better a way of finding a control on WinForm than to use a
| recursive method on the controls collection property? I ask this question
| because I have winforms which have many controls on it and the function
| takes a long time to beexecuted. This is my function
|
| Public Function FindControl(ByVal oControls As Control.ControlCollection,
| ByVal strControlName As String) As Control
|
| Dim MyCtl As Control
|
| For Each MyCtl In oControls
| If MyCtl.Name = strControlName Then
| Return MyCtl
|
| Else
| If MyCtl.Controls.Count > 0 Then
| Return FindControl(MyCtl.Controls, strControlName)
|
| End If
|
| End If
|
| Next
|
| End Function
|
| Thank you
|
| --
| Marc R.
| E-mail
| Dim strAddr As String =Convert.ToString(String.Format("{0}.{2}@{3}.{1}",
| "mxrc", "cx", "robitxille", "xrs-solutions")).Replace("x", "a")
|
|