Delete controls in a FlowLayoutPanel


I want to delete every Control in a FlowLayoutPanel which have "GT" in their names. I do it like this:

        For Each Control As Control In Me.FlowLayoutPanel1.Controls
            If InStr(Control.Name, "GT") Then
                Control = Nothing
            End If

This works great, but because of a reason I can't figure out only half of the controls gets deleted. Which means I will need to run this code 4 times to delete 8 Controls.
8 -> 4 -> 2 -> 1 -> 0

Does anyone know how I  can do this the right way?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OlcayKAuthor Commented:
I got it working on my own...

Use this if you have a similar problem yourelf:

        Dim i As Integer = Me.FlowLayoutPanel1.Controls.Count - 1
        Do While i > -1
            If InStr(Me.FlowLayoutPanel1.Controls(i).Name, "GT") Then
            End If

            i = i - 1
For iCnt As Integer = Me.FlowLayoutPanel1.Controls.Count - 1 To 0 Step -1
            Dim ctrl As Control = Me.FlowLayoutPanel1.Controls(iCnt)

            Console.WriteLine("before delete :" & ctrl.Name)
            If InStr(ctrl.Name, "GT") Then
                Console.WriteLine("deleted :" & ctrl.Name)
                ctrl = Nothing

            End If

sorry, when i started entering my response your second post was not there
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

OlcayKAuthor Commented:
I dont know if this is ok, but I would like to know something else... I willl give the 250 points to this simple question:

How can I determine the X value of an array like this: Array(X, Y)

Dim Array as Array(5, 2)
How can I get the "5"?
use getupperbound method as follows

Console.WriteLine(Array.GetLowerBound(0))      'returns 0
        Console.WriteLine(Array.GetLowerBound(1))  'returns 0
        Console.WriteLine(Array.GetUpperBound(0)) 'returns 5
        Console.WriteLine(Array.GetUpperBound(1)) 'returns 2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OlcayKAuthor Commented:
Hi appari... Seems like the point will go to you here... I saw your expert points and hope you can help me with a small thing first...

Lets say I have 2 controls in a FlowLayoutPanel and need to add a component between these two. How can I accomplish this?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.