Databindings Question

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
 
G

Guest

Martin,

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

Kerry Moorman
 
M

Martin Horn

Thanks Kerry, that did it.

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

Martin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top