|
-
Apr 30th, 2012, 05:16 PM
#1
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?
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Apr 30th, 2012, 05:33 PM
#2
Re: Loop Through Buttons And Skip Certain Ones
-
Apr 30th, 2012, 05:37 PM
#3
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
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Apr 30th, 2012, 05:46 PM
#4
Fanatic Member
Re: Loop Through Buttons And Skip Certain Ones
-
Apr 30th, 2012, 05:46 PM
#5
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)
-
Apr 30th, 2012, 05:54 PM
#6
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. 
vb Code:
If String.Compare(CType(c, Button).Name, btnfunction.Name, True) = 0 Then
' just skip
Else
' do something
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|