Rellenar botones de radio de la tabla de datos

I'm making a questback in Windows forms (VB). I've succesfully setup the MySQL-database, and made connection with everything needed. I've also manage to populate a DataTable called tblAlt for the alternatives for the question.

Then I try to populate each radiobutton with rows from the DataTable.

Esto es lo que intenté:

For Each row In tblAlt.Rows
    If tblAlt.Rows.IndexOf(row) = 0 Then
        RadioButton1.DataBindings.Add("Text", bindAlt, "altTekst")
    ElseIf tblAlt.Rows.IndexOf(row) = 1 Then
        RadioButton2.DataBindings.Add("Text", bindAlt, "altTekst")
    ElseIf tblAlt.Rows.IndexOf(row) = 3 Then
        RadioButton3.DataBindings.Add("Text", bindAlt, "altTekst")
    End If

Unfortunately all 3 radiobuttons have the same text (the first row of the table).

preguntado el 03 de mayo de 12 a las 12:05

Where are you setting the bindAlt variable? -

2 Respuestas

You don't generally data bind individual rows of a table to controls on a form. In your example code, you are databinding the same thing every time.

I suspect, this is all you want:

For Each row As DataRow In tblAlt.Rows
  If tblAlt.Rows.IndexOf(row) = 0 Then
    RadioButton1.Text = row("altTekst").ToString
  End If
  If tblAlt.Rows.IndexOf(row) = 1 Then
    RadioButton2.Text = row("altTekst").ToString
  End If
  If tblAlt.Rows.IndexOf(row) = 2 Then
    RadioButton3.Text = row("altTekst").ToString
  End If

contestado el 03 de mayo de 12 a las 14:05

Studentactive.lblcourse.Text = dgvstclass2.Rows(e.RowIndex).Cells("Course Name").Value Studentactive.lblTeacher.Text = dgvstclass2.Rows(e.RowIndex).Cells("Teacher Name").Value Studentactive.lbltiming.Text = dgvstclass2.Rows(e.RowIndex).Cells("Timing").Value Studentactive.lblhide.Text = dgvstclass2.Rows(e.RowIndex).Cells("Rec#").Value

Respondido el 28 de enero de 17 a las 16:01

Could you please explain exactly what this code ? Posting a block of code by itself with no context isn't helpful. - Michael Dodd

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.