Radio Button Choice Displaying in a MessageBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sarge
    New Member
    • May 2007
    • 5

    #1

    Radio Button Choice Displaying in a MessageBox

    Hello, I have a group box (grpButtons) with four radio buttons (radAbortRetryI gnore, radOK, radOKCancel, radYesNo) what I am trying to do is display the buttons in the messagebox based on the selection the user makes with the radio buttons.

    MessageBox.Show (txtTitle.Text, txtMessage.Text , grpButtons())

    where I have grpButtons() is where Im having the problem, Im trying to have the message box display what the user chooses. Can this be done with an array???? I have tried several different ways and keep getting errors. Any help would be appreciated.

    Thank You in Advance. I am enclosing what I have done so far, If I could get a push in the right direction as to how to tie in the radio button selected to the message box i will be able to figure out the rest

    P.S. How do I upload the project if need be????
  • Sarge
    New Member
    • May 2007
    • 5

    #2
    Sorry, I am using VB.Net version 2003

    Comment

    • shidec
      New Member
      • May 2007
      • 26

      #3
      if u want use array u can write like this

      Code:
      Public Class Form1
      
          Private radChoice(4) As RadioButton
          Private selectedIndex As Integer
      
          Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              radChoice(0) = radChoice0
              radChoice(1) = radChoice1
              radChoice(2) = radChoice2
              radChoice(3) = radChoice3
          End Sub
      
          Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
              MessageBox.Show(radChoice(selectedIndex).Text)
          End Sub
      
          Private Sub radChoice0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radChoice0.Click, radChoice3.Click, radChoice2.Click, radChoice1.Click
              Dim rb As RadioButton
              rb = CType(sender, RadioButton) 'use sender argument to determine wich radio button clicked
              selectedIndex = rb.Tag   'every tag property of radio button must set first
              MessageBox.Show(rb.Text) 'just try to show message when radio button click
          End Sub
      
      End Class

      if u just want to show message according to radio button selected
      Code:
      Public Class Form1
      
          Private sMessage as String
          Private selectedIndex As Integer
      
          Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
              MessageBox.Show(sMessage)
          End Sub
      
          Private Sub radChoice0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radChoice0.Click, radChoice3.Click, radChoice2.Click, radChoice1.Click
              Dim rb As RadioButton
              rb = CType(sender, RadioButton) 'use sender argument to determine wich radio button clicked
              sMessage = rb.Text
              MessageBox.Show(rb.Text) 'just try to show message when radio button click
          End Sub
      
      End Class

      Note:
      There is only one radio button click event to handle all of radio button.
      So every radio button must refer to this event

      Comment

      Working...