I
Ishmael
I'm trying to find all the objects in a form whose name begins with
some string, for example "textBox1", "textBox2", "textBox3".
I tried to modify the code from this reference
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.name(VS.85).aspx
but I'm having trouble adding new controls to a ControlCollection.
The error I'm getting is:
"Object reference not set to an instance of an object."
Here's my code:
Control::ControlCollection ^controls;
// Loop through all controls in the form's control collection.
IEnumerator^ myEnum = this->Controls->GetEnumerator();
while ( myEnum->MoveNext() )
{
Control^ tempCtrl = safe_cast<Control^>(myEnum->Current);
if (tempCtrl->Name->StartsWith("mystring")) {
controls->Add(tempCtrl);
}
}
return(controls);
There's something I'm missing here. Any help will be greatly
appreciated!
some string, for example "textBox1", "textBox2", "textBox3".
I tried to modify the code from this reference
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.name(VS.85).aspx
but I'm having trouble adding new controls to a ControlCollection.
The error I'm getting is:
"Object reference not set to an instance of an object."
Here's my code:
Control::ControlCollection ^controls;
// Loop through all controls in the form's control collection.
IEnumerator^ myEnum = this->Controls->GetEnumerator();
while ( myEnum->MoveNext() )
{
Control^ tempCtrl = safe_cast<Control^>(myEnum->Current);
if (tempCtrl->Name->StartsWith("mystring")) {
controls->Add(tempCtrl);
}
}
return(controls);
There's something I'm missing here. Any help will be greatly
appreciated!