OlcayK
asked on
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.Contro ls
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?
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.Contro
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?
For iCnt As Integer = Me.FlowLayoutPanel1.Contro ls.Count - 1 To 0 Step -1
Dim ctrl As Control = Me.FlowLayoutPanel1.Contro ls(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
Dim ctrl As Control = Me.FlowLayoutPanel1.Contro
Console.WriteLine("before delete :" & ctrl.Name)
If InStr(ctrl.Name, "GT") Then
Console.WriteLine("deleted
ctrl.Dispose()
ctrl = Nothing
End If
Next
sorry, when i started entering my response your second post was not there
ASKER
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"?
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"?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
Lets say I have 2 controls in a FlowLayoutPanel and need to add a component between these two. How can I accomplish this?
ASKER
Use this if you have a similar problem yourelf:
Dim i As Integer = Me.FlowLayoutPanel1.Contro
Do While i > -1
If InStr(Me.FlowLayoutPanel1.
Me.FlowLayoutPanel1.Contro
End If
i = i - 1
Loop