Share via

Radiobuttons Databinding VB.Net

Hobbyist_programmer 621 Reputation points
2021-07-12T17:13:58.073+00:00

Hallo,

I am trying to make radio buttons binding, it is exactly similar to the thread below,

https://social.msdn.microsoft.com/Forums/windows/en-US/8eb7bcf0-8282-4e7d-9218-98462e5315af/radio-buttons-data-binding?forum=winforms

I have converted the C code to VB.net but i having following errors, could anyone fix this .

Public Class BBRadioButtonString  
    Inherits RadioButton  
  
    Protected oBinding As Binding = Nothing  
    Protected bs As BindingSource = New BindingSource()  
    Protected DataValue As String = ""  
  
    Public Overridable Sub DataBind(ByVal bindingSource As BindingSource, ByVal Column As String, ByVal Optional dataValue As String = "")  
        Me.Checked = False  
        Me.bs = bindingSource  
        Me.oBinding = New Binding("Checked", Me.bs, Column)  
  
        If dataValue <> "" Then  
            Me.DataValue = dataValue  
        Else  
            Me.DataValue = Me.Text  
        End If  
  
        Me.oBinding.Format = New ConvertEventHandler(AddressOf Me.FormatHandler)  
        oBinding.Parse += New ConvertEventHandler(AddressOf Me.ParseHandler)  
        Validated += New EventHandler(AddressOf Me.ValidatedHandler)  
        DataBindings.Add(Me.oBinding)  
    End Sub  
  
    Protected Overridable Sub FormatHandler(ByVal sender As Object, ByVal e As ConvertEventArgs)  
        If e.Value.ToString() = Me.DataValue Then  
            e.Value = True  
        Else  
            e.Value = False  
        End If  
    End Sub  
  
    Protected Overridable Sub ParseHandler(ByVal sender As Object, ByVal e As ConvertEventArgs)  
        If CBool(e.Value) = True Then e.Value = Me.DataValue  
        Me.bs.EndEdit()  
    End Sub  
  
    Private Sub ValidatedHandler(ByVal sender As Object, ByVal e As EventArgs)  
        Me.bs.EndEdit()  
    End Sub  
End Class  

113965-2021-07-12-19-12-11.png

It says i have to use Raise event

Tahnks

Developer technologies | VB
0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2021-07-12T17:44:32.63+00:00

The syntax is different:

AddHandler oBinding.Format, AddressOf Me.FormatHandler
AddHandler oBinding.Parse, AddressOf Me.ParseHandler
AddHandler Validated, AddressOf Me.ValidatedHandler

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.