Results 1 to 7 of 7

Thread: Option Button OCX

  1. #1
    Brian
    Guest

    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!

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It automatically will handle that for you with a normal option control.

  3. #3
    Brian
    Guest
    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. =)

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. If UserControl.Ambient.UserMode = True Then
    2.     Dim ctrl As Control
    3.     For Each ctrl In Me.Parent.Controls
    4.         If TypeName(ctrl)="MyUserControl" And ctrl.name<>me.name then
    5.              ctrl.Value=false
    6.         End If
    7.     Next
    8.     End If

    This code will given an error because of the Parent use but it should give you an idea where to go.

  5. #5
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    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.


  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  7. #7
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    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
  •  



Click Here to Expand Forum to Full Width