Home All Groups Group Topic Archive Search About

Assign a value to groupbox from a radiobutton contained in groupbo

Author
4 Aug 2006 8:15 PM
Rich
Hello,

Is it possible to assign a value to a groupbox by selecting a radiobutton
contained in the groupbox?

Say you assign a value of 1 to radbtn1, 2 for radbtn2, 3 for radbtn3 all
contained in grpBox.  You click radbtn1.

Console.writeline(grpBox.Value.ToString)

Is there a way to do something like this?  (VB2005)

Thanks,
Rich

Author
4 Aug 2006 8:22 PM
Herfried K. Wagner [MVP]
"Rich" <R***@discussions.microsoft.com> schrieb:
> Is it possible to assign a value to a groupbox by selecting a radiobutton
> contained in the groupbox?
>
> Say you assign a value of 1 to radbtn1, 2 for radbtn2, 3 for radbtn3 all
> contained in grpBox.  You click radbtn1.
>
> Console.writeline(grpBox.Value.ToString)
>
> Is there a way to do something like this?  (VB2005)

Add a common event handler to all the radio buttons which belong to a group:

\\\
Private m_Group1SelectedRadioButton As RadioButton

Private Sub RadioButtonGroup1_CheckedChanged( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
) Handles _
    RadioButton1.CheckedChanged, _
    RadioButton2.CheckedChanged, _
    RadioButton3.CheckedChanged

    Dim SourceControl As RadioButton = DirectCast(sender, RadioButton)
    If SourceControl.Checked Then
        m_Group1SelectedRadioButton = SourceControl
    End If
End Sub
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
4 Aug 2006 8:46 PM
Rich
Thank you very much.  That was just what I was looking for.

Rich

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Rich" <R***@discussions.microsoft.com> schrieb:
> > Is it possible to assign a value to a groupbox by selecting a radiobutton
> > contained in the groupbox?
> >
> > Say you assign a value of 1 to radbtn1, 2 for radbtn2, 3 for radbtn3 all
> > contained in grpBox.  You click radbtn1.
> >
> > Console.writeline(grpBox.Value.ToString)
> >
> > Is there a way to do something like this?  (VB2005)
>
> Add a common event handler to all the radio buttons which belong to a group:
>
> \\\
> Private m_Group1SelectedRadioButton As RadioButton
>
> Private Sub RadioButtonGroup1_CheckedChanged( _
>     ByVal sender As Object, _
>     ByVal e As EventArgs _
> ) Handles _
>     RadioButton1.CheckedChanged, _
>     RadioButton2.CheckedChanged, _
>     RadioButton3.CheckedChanged
>
>     Dim SourceControl As RadioButton = DirectCast(sender, RadioButton)
>     If SourceControl.Checked Then
>         m_Group1SelectedRadioButton = SourceControl
>     End If
> End Sub
> ///
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>