PC Review


Reply
Thread Tools Rate Thread

Databindings Question

 
 
Martin Horn
Guest
Posts: n/a
 
      29th Mar 2005
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      29th Mar 2005
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
>
>
>

 
Reply With Quote
 
Martin Horn
Guest
Posts: n/a
 
      29th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:3384CA17-EC5C-4402-BAFB-(E-Mail Removed)...
> 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
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about using DataBindings BobRoyAce Microsoft Dot NET Framework Forms 3 17th Jan 2008 06:21 AM
Label Databindings are reset upon edit databindings via smart tag =?Utf-8?B?UFc=?= Microsoft ASP .NET 0 24th Apr 2006 12:10 AM
Databindings Question whaletyr Microsoft VB .NET 2 19th May 2004 03:30 PM
Databindings question whaletyr Microsoft ASP .NET 2 19th May 2004 03:17 PM
DataBindings bug? Jorge Cavalheiro Microsoft VB .NET 0 2nd Sep 2003 10:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:08 PM.