473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Databindings Question

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
2 1981
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex Bibiano | last post by:
I have a typed dataset in my WinForm and a textbox with databinding to the dataset (all without code). Now, in a button event, I assign a new dataset (retrieved from a function) to the dataset a...
0
by: Johann Blake | last post by:
I have a form with textboxes that are bound to a dataset. The dataset contains two tables and some of the textboxes use data from one table while other textboxes use data from the other table. I...
9
by: HAN(removethis)twister | last post by:
I've tried to create 11 textboxes as variables (not actually visible in the program, not in Windows Form Designer) and have set DataBindings to the text properties of the TextBoxes BUT according to...
6
by: Graham Blandford | last post by:
Hi all, I haven't received any replies to a previous question I posted regarding problems I was having with databound textboxes.. so I'll try a different angle... Can anyone point me in the...
2
by: C Glenn | last post by:
This is admitedly vague. But so is my understanding of the problem. I'm using this chunk of code: retControl.DataBindings.Add(ctrlBinding.PropertyName,DataSource,BindingField); This resolves...
0
by: XenReborn | last post by:
Ok this should be simple. I made a form, added a combobox (for selecting items to edit, not for updating fields), several textboxes, a few checkboxes etc. On formshow it connects to my database,...
2
by: marcf | last post by:
Hi everyone, I've just studio using VS2008 and have a quick question regarding databindings, i'm fairly handy with vb6 so this question really relates to good practice rather than actual coding. ...
7
by: =?Utf-8?B?Tmljb2xhcw==?= | last post by:
Yes another question about databindings. All my controls are have databindings and works fine for navigating, adding, deleting etc. What I want is when I create a New record have those fields...
1
by: janj | last post by:
Hi all, I'm having a problem binding two object properties to properties of another object. The code below works as expected when only one binding is added but doesn't work at all (still compiles)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.