• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

Delete controls in a FlowLayoutPanel

Hi!

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.Dispose()
                Control = Nothing
            End If
        Next

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?
0
OlcayK
Asked:
OlcayK
  • 3
  • 3
1 Solution
 
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
                Me.FlowLayoutPanel1.Controls.Remove(Me.FlowLayoutPanel1.Controls(i))
            End If

            i = i - 1
        Loop
0
 
appariCommented:
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.Dispose()
                ctrl = Nothing

            End If
        Next
0
 
appariCommented:

sorry, when i started entering my response your second post was not there
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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"?
0
 
appariCommented:
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
0
 
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?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now