BobH

Hello All,

I am trying to use the for each on a Controls collection as I had in C# but I can't seem to get it working.

Any help would be appreciated Smile

Bob Hanson




Re: Visual C++ General Example iterating through a Controls Collection using for each in C++/CLI

crescens2k

Well, could you post the code you have since that would be the best way to help you out.






Re: Visual C++ General Example iterating through a Controls Collection using for each in C++/CLI

Bite Qiu - MSFT

BobH wrote:

Hello All,

I am trying to use the for each on a Controls collection as I had in C# but I can't seem to get it working.

Any help would be appreciated

Bob Hanson

Hi Bob,

As crescens2k indicated, provide your existing code is more appropriate way to help you out. Since you are mentioned examples of iterating through a control collection, here is a simple one that works for me:

Create a winform application use wizard, add a button and some other controls including one or more text box, then in the button click event handler, add following code to iterate through the controls in control collection:

Code Snippet

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
for each(Control ^pC in this->Controls){
if(pC->GetType() == System::Windows::Forms::TextBox::typeid)
pC->Text = "whatever";
}
}

hope it helps

rico