|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Databindings QuestionI 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 Show quoteHide quote "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 > > > Thanks Kerry, that did it.
To be honest I thought I had already tried that, must have got confused somewhere along the line. Martin. Show quoteHide quote "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message news:3384CA17-EC5C-4402-BAFB-7A91E224F560@microsoft.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 >> >> >> |
|||||||||||||||||||||||