|
-
Apr 18th, 2002, 10:32 AM
#1
Option Button OCX
Say I have two option buttons in a form. When I select one of them, the other one gets unselected. How can I do this? I'm asking this coz I want to make my own customizable option button. Thanks in advance!
-
Apr 18th, 2002, 10:49 AM
#2
It automatically will handle that for you with a normal option control.
-
Apr 20th, 2002, 11:30 AM
#3
Thanks for replying!
But what I need is how 'exactly' did they do the normal option button? That when you click on option2, option1 will be unselected. I want to know how to link 2 different controls that's applied on a form. =)
-
Apr 20th, 2002, 02:37 PM
#4
You'd have to loop through any controls of the same type on the same container. Hmmm I'm not sure what the best way is to get the container of your control, it seems that there should be some form of ambient property for it. I've only had to get the hWnd of the parent. But if you can get that then use somethign like this:
VB Code:
If UserControl.Ambient.UserMode = True Then
Dim ctrl As Control
For Each ctrl In Me.Parent.Controls
If TypeName(ctrl)="MyUserControl" And ctrl.name<>me.name then
ctrl.Value=false
End If
Next
End If
This code will given an error because of the Parent use but it should give you an idea where to go.
-
Apr 24th, 2002, 07:58 PM
#5
PowerPoster
I was thinking of the same idea but it's flawed becasue it won't work if the user changes the default name of the control.
Like i have 2 option buttons and one is named option1 and the other one is named optMyOptionButton. So you can't compare the controls by name.
This one has me puzzled.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 24th, 2002, 08:53 PM
#6
You lost me there, he is making a usercontrol so me.name is the name of the current control even if it gets changed and it is only comparing ctrl.name with it so that it doesn't set it's own value to false. Or did I misunderstand what you were saying? What is flawed?
The code loops through all controls that are the same as it on the same container. If the control isn't the one that is running the code then it sets that control's value to false.
P.S. "MyUserControl" isn't the control name it's the TypeName like Textbox is for a textbox.
Last edited by Edneeis; Apr 24th, 2002 at 08:56 PM.
-
Apr 25th, 2002, 12:08 AM
#7
PowerPoster
ahh ok. I saw TypeName and assumed you were comparing by name. Whereas i am used to seeing TypeOf which compares the typeof Control it is.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

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
|