Bind textbox to a public property in business class

M

moondaddy

I have a sample data entry form where I want to bind the controls to
properties residing in the supporting business class for better handling of
business logic (as apposed to binding straight to a dataset). My old way is
to manually load data into each control via a SetState method and writing
data to the biz class would be performed on the TextChanged event. I was
interested in seeing if there was a better way to do this such as binding
the textbox to the property in the biz class. However, one thing that may
not work too good for example is when I need to enter a date value. The
date value gets tested in the property to see if its a valid date. If not,
then it sets the property back to the original value, otherwise the new
value is written to the property. In the Leave event the value of the
property is written back to the control so the control is assured to have a
valid value in it. This might be too complicated of process for simply
binding the textbox to the property. Is there a good .NET way of doing
this?
 
K

Ken Tucker [MVP]

Hi,

You can bind a textbox to an arraylist or any object that implements
iBindingList or iTypedList interface. Here is an example that binds to an
arraylist arClass and property Col2.

TextBox1.DataBindings.Add("Text", arClass, "Col2")

Ken
 
M

moondaddy

Thanks. I've used an arraylistbefore for the datasource of a combo box, but
in this case I want to bind to a public property in my business class which
could look something like this:

Public Property Or_Cu_ID() As Int32
Get
Return m_BDR.Or_Cu_ID
End Get
Set(ByVal Value As Int32)
m_BDR.Or_Cu_ID = Value
End Set
End Property

Maybe I'm trying to steer this the wrong way, but it seemed like a good
idea.


Ken Tucker said:
Hi,

You can bind a textbox to an arraylist or any object that implements
iBindingList or iTypedList interface. Here is an example that binds to an
arraylist arClass and property Col2.

TextBox1.DataBindings.Add("Text", arClass, "Col2")

Ken

----------------------------

moondaddy said:
I have a sample data entry form where I want to bind the controls to
properties residing in the supporting business class for better handling of
business logic (as apposed to binding straight to a dataset). My old
way
is
to manually load data into each control via a SetState method and writing
data to the biz class would be performed on the TextChanged event. I was
interested in seeing if there was a better way to do this such as binding
the textbox to the property in the biz class. However, one thing that may
not work too good for example is when I need to enter a date value. The
date value gets tested in the property to see if its a valid date. If not,
then it sets the property back to the original value, otherwise the new
value is written to the property. In the Leave event the value of the
property is written back to the control so the control is assured to
have
 
Y

Ying-Shen Yu[MSFT]

Hi moondaddy,
You may take a loot at IEditableObject interface and the IBindingList
interface,
The first interface will enable editing property of your object in your
data-bound control
and second interface will let your object be able to bind to data-bound
control.
Compare with IList interface, IBindingList let you be able to notify the
data-bound control when the underlying data changes.
You may look at this article in MSDN and get an idea on Data-Binding
related interfaces

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbconinterfacesrelatedtodatabinding.asp

Please be free to let me know if you have any further questions on this
issue.
Thanks for using MSDN Newsgroup!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "moondaddy" <[email protected]>
| Subject: Bind textbox to a public property in business class
| Date: Wed, 15 Oct 2003 09:41:59 -0500
| Lines: 20
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#OOs#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: adsl-66-137-118-208.dsl.hstntx.swbell.net
66.137.118.208
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54496
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a sample data entry form where I want to bind the controls to
| properties residing in the supporting business class for better handling
of
| business logic (as apposed to binding straight to a dataset). My old way
is
| to manually load data into each control via a SetState method and writing
| data to the biz class would be performed on the TextChanged event. I was
| interested in seeing if there was a better way to do this such as binding
| the textbox to the property in the biz class. However, one thing that may
| not work too good for example is when I need to enter a date value. The
| date value gets tested in the property to see if its a valid date. If
not,
| then it sets the property back to the original value, otherwise the new
| value is written to the property. In the Leave event the value of the
| property is written back to the control so the control is assured to have
a
| valid value in it. This might be too complicated of process for simply
| binding the textbox to the property. Is there a good .NET way of doing
| this?
|
| --
| (e-mail address removed)
|
|
|
 
Y

Ying-Shen Yu[MSFT]

Hi moondaddy,
You may take a look at IEditableObject interface and the IBindingList
interface,The first interface will enable editing property of your object
in your data-bound control and second interface will let your object be
able to bind to data-bound control. Compare with IList interface,
IBindingList let you be able to notify the data-bound control when the
underlying data changes. You may look at this article in MSDN and get an
idea on Data-Binding related interfaces

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbconinterfacesrelatedtodatabinding.asp

Please be free to let me know if you have any further questions on this
issue.
Thanks for using MSDN Newsgroup!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "moondaddy" <[email protected]>
| Subject: Bind textbox to a public property in business class
| Date: Wed, 15 Oct 2003 09:41:59 -0500
| Lines: 20
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#OOs#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: adsl-66-137-118-208.dsl.hstntx.swbell.net
66.137.118.208
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54496
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a sample data entry form where I want to bind the controls to
| properties residing in the supporting business class for better handling
of
| business logic (as apposed to binding straight to a dataset). My old way
is
| to manually load data into each control via a SetState method and writing
| data to the biz class would be performed on the TextChanged event. I was
| interested in seeing if there was a better way to do this such as binding
| the textbox to the property in the biz class. However, one thing that may
| not work too good for example is when I need to enter a date value. The
| date value gets tested in the property to see if its a valid date. If
not,
| then it sets the property back to the original value, otherwise the new
| value is written to the property. In the Leave event the value of the
| property is written back to the control so the control is assured to have
a
| valid value in it. This might be too complicated of process for simply
| binding the textbox to the property. Is there a good .NET way of doing
| this?
|
| --
| (e-mail address removed)
|
|
|
 

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

Top