Databindings Question

  • Thread starter Thread starter Martin Horn
  • Start date Start date
M

Martin Horn

Hi,

I want to use databinding on a property for a class that I have created, but
I can't make it work. Below is a contrived example to illustrate the
problem.

It seems that I can't databind properties that I have created, is there a
way to do this?

Thanks,

Martin.

Public Class Form1

Public Class Class1
Inherits Button
Public MyValue As String = "Default Value"
End Class

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim t As New Class1

' This line would work as expected
' ----------------------------------
' TextBox1.DataBindings.Add("Text", t, "Size")

' This line causes runtime error:
' Cannot bind to property or column MyValue on DataSource.
' Parameter name: dataMember
' -------------------------------------------------------------
TextBox1.DataBindings.Add("Text", t, "MyValue")
End Sub

End Class
 
Martin,

You might try making MyValue a public property instead of a public field.

Kerry Moorman
 
Thanks Kerry, that did it.

To be honest I thought I had already tried that, must have got confused
somewhere along the line.

Martin.
 
Back
Top