By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,558 Members | 1,699 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,558 IT Pros & Developers. It's quick & easy.

Databindings Question

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Martin,

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

Kerry Moorman
"Martin Horn" wrote:
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

Nov 21 '05 #2

P: n/a
Thanks Kerry, that did it.

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

Martin.

"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:33**********************************@microsof t.com...
Martin,

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

Kerry Moorman
"Martin Horn" wrote:
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.