Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple entries... One RichTextBox

Status
Not open for further replies.

richself

Technical User
Jun 27, 2005
37
US
I'm writting to a Database. I have a form that I would like to use just one Rich Text Box that will fill 8 different Columns in a database. I've put 8 Radio Buttons in a group box. I'd like the user to select a button, fill in the text box, then select another button to fill in the text box again with text relivent to that button and so on. Right now I have

if oneRadioButton.checked then
cRow("one") = textbox.text
elseif twoRadioButton.checked then
cRow("two") = textbox.text

this of coarse, does not allow me to cycle through all the buttons.

Ideas?

Thanks
 
You might try something like this:

Code:
  Private CurrentRadioButton As Integer = 0

  Private Sub GroupBox1RadioButton_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
        RadioButton1.Click, RadioButton2.Click, RadioButton3.Click


    Dim rb As RadioButton
    'This assumes that the RadioButtons are in a GroupBox called GroupBox1

    '****This allows pre-selection of field by RadioButton and then updates field when another rb is clicked:
    For Each ctl As Control In GroupBox1.Controls
      If TypeOf ctl Is RadioButton Then
        If ctl.TabIndex = CurrentRadioButton Then
          rb = CType(ctl, RadioButton)
          Exit For
        End If
      End If
    Next
    Select Case CurrentRadioButton
      Case 0
        MessageBox.Show(rb.Name)
      Case 1
        MessageBox.Show(rb.Name)
      Case 2
        MessageBox.Show(rb.Name)
    End Select
    CurrentRadioButton = CType(sender, RadioButton).TabIndex

    '****This allows post-selection of field ie RichTextBox is filled in when the RadioButton is clicked
    rb = CType(sender, RadioButton)
    Select Case rb.TabIndex
      Case 0
        MessageBox.Show(rb.Name)
      Case 1
        MessageBox.Show(rb.Name)
      Case 2
        MessageBox.Show(rb.Name)
    End Select

  End Sub


A couple of points:

You can't create this event handler in the normal way, the easiest way would be to copy my heading line:

Private Sub GroupBox1RadioButton_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _

and then add your RadioButtons to the Handles statement as RadioButtonOneName.Click, RadioButtonTwoName.Click and so on.

Only use one of the alternatives (ie pre- or post- selection).

If you use post-selection you don't need the CurrentRadioButton variable.

Where I've used MessageBox you would put the code that updates the appropriate column.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top