Loop Through Buttons And Skip Certain Ones
This is probably one of those crazy simple things, but it's been a long day and I'm having trouble figuring it out.
I loop through all of the buttons in a panel. If the button's name is not the name of the btnFunction, then I need to add that control to a list. But it adds the function button either way.
Code:
For Each c As Control In Me.pnKybdNormal.Controls
If TypeOf c Is Button Then
If Not CType(c, Button).Name = btnFunction.Name Then
'Everything works correctly, except the btnFunction isn't skipped
End If
End If
Next
Anyone know what I'm doing wrong here?
Re: Loop Through Buttons And Skip Certain Ones
Re: Loop Through Buttons And Skip Certain Ones
It doesn't make sense why that wouldn't work. Try this
Code:
If c IsNot btnFunction Then
'work
End If
Re: Loop Through Buttons And Skip Certain Ones
Re: Loop Through Buttons And Skip Certain Ones
Will probably have the same result if your first post does not work...
vb Code:
Dim buttons = Me.Controls.OfType(Of Button).ToArray.Where(Function(b As Button) Not b.Name = btnFunction.Name)
Array.ForEach(buttons.ToArray, Sub(b As Button) b.BackColor = Color.Black)
Re: Loop Through Buttons And Skip Certain Ones
Your code works perfect here!!!
Try to add break point and check control names.
Also when something be crazy, i try a crazy code. :sick:
vb Code:
If String.Compare(CType(c, Button).Name, btnfunction.Name, True) = 0 Then
' just skip
Else
' do something
End If