473,473 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataBinding a TextBox to an Object

I've been having problems with databinding. I've created a simple
solution to emulate the problem I can't figure out. Basically, I have a
TextBox bound to a property in an object. When the property is updated,
how do I get the field to show the new value. I assumed that databinding
would take care of it automatically.

Here is my source code. Can someone tell me what I would need to do to
get TextBox2 to update after the f.value is changed? (The form as one
button (Button1) and two TextBox fiels (TextBox1 & TextBox2)

Public Class Form1
Private f As New Field

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Set up binding
f.value = "test"
Me.TextBox2.DataBindings.Add("Text", f, "value", False,
DataSourceUpdateMode.OnPropertyChanged)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
f.value = Me.TextBox1.Text
End Sub
End Class

Public Class Field
Private sValue As String

Public Property value() As String
Get
Return sValue
End Get
Set(ByVal val As String)
Me.sValue = val
End Set
End Property
End Class

Thanks,
Dustin
Mar 16 '07 #1
2 8994
Found a solution: http://www.15seconds.com/issue/040910.htm

Here is my updated code in case anyone cares:
Public Class Form1
Private f As New Field

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Set up binding
f.value = "test"
Me.TextBox2.DataBindings.Add("Text", f, "value")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
f.value = Me.TextBox1.Text
End Sub
End Class

Public Class Field
Private sValue As String
Dim bs As BindingSource

Public Event valueChanged As Eventhandler

Public Property value() As String
Get
Return sValue
End Get
Set(ByVal val As String)
Me.sValue = val
RaiseEvent valueChanged(Me, New EventArgs())
End Set
End Property
End Class
Dustin Davis wrote:
I've been having problems with databinding. I've created a simple
solution to emulate the problem I can't figure out. Basically, I have a
TextBox bound to a property in an object. When the property is updated,
how do I get the field to show the new value. I assumed that databinding
would take care of it automatically.

Here is my source code. Can someone tell me what I would need to do to
get TextBox2 to update after the f.value is changed? (The form as one
button (Button1) and two TextBox fiels (TextBox1 & TextBox2)

Public Class Form1
Private f As New Field

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Set up binding
f.value = "test"
Me.TextBox2.DataBindings.Add("Text", f, "value", False,
DataSourceUpdateMode.OnPropertyChanged)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
f.value = Me.TextBox1.Text
End Sub
End Class

Public Class Field
Private sValue As String

Public Property value() As String
Get
Return sValue
End Get
Set(ByVal val As String)
Me.sValue = val
End Set
End Property
End Class

Thanks,
Dustin
Mar 16 '07 #2

Private Sub SetLocalDataBindings()

If (Me.m_arg.ViewMode <EventArgs.ViewMode.AddNew) Then

Dim titleIdBinding As Binding = _
txtTitleId.DataBindings.Add("Text", Me.m_model, "TitleId")

'Improved in .NET 2.0 //
http://msdn2.microsoft.com/library/y...us,vs.80).aspx
'titleIdBinding.NullValue = "Type a TitleID Here"

AddHandler titleIdBinding.Format, AddressOf BindingNullCheck
''AddHandler titleIdBinding.Parse, AddressOf BindingNullCheck

'''Me.txtTitleId.DataBindings.Add(New Binding("Text",
Me.m_model, "TitleId"))

Me.txtPubId.DataBindings.Add(New Binding("Text", Me.m_model,
"CurrentPublisher.PublisherId"))
Me.txtTitle.DataBindings.Add(New Binding("Text", Me.m_model,
"Title"))
Me.txtPublisher.DataBindings.Add(New Binding("Text", Me.m_model,
"CurrentPublisher.PublisherName"))

Me.txtType.DataBindings.Add(New Binding("Text", Me.m_model,
"TitleType"))

Me.dtpPubDate.DataBindings.Add(New Binding("Value", Me.m_model,
"PublishedDate"))
Me.txtPubDate.DataBindings.Add(New Binding("Text", Me.m_model,
"PublishedDate"))

End If

If Not (Me.m_model.AllPublishers Is Nothing) Then
Me.cboPublisher.DataSource = Me.m_model.AllPublishers
Me.cboPublisher.DataBindings.Add(New Binding("SelectedItem",
Me.m_model, "CurrentPublisher"))
End If

End Sub

"Dustin Davis" <du****@davisvillage.comwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
I've been having problems with databinding. I've created a simple
solution to emulate the problem I can't figure out. Basically, I have a
TextBox bound to a property in an object. When the property is updated,
how do I get the field to show the new value. I assumed that databinding
would take care of it automatically.

Here is my source code. Can someone tell me what I would need to do to
get TextBox2 to update after the f.value is changed? (The form as one
button (Button1) and two TextBox fiels (TextBox1 & TextBox2)

Public Class Form1
Private f As New Field

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Set up binding
f.value = "test"
Me.TextBox2.DataBindings.Add("Text", f, "value", False,
DataSourceUpdateMode.OnPropertyChanged)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
f.value = Me.TextBox1.Text
End Sub
End Class

Public Class Field
Private sValue As String

Public Property value() As String
Get
Return sValue
End Get
Set(ByVal val As String)
Me.sValue = val
End Set
End Property
End Class

Thanks,
Dustin

Mar 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert Ludig | last post by:
How do I bind a textbox to a simple string varaible with databinding? I managed to do the binding but unfortnatedly the textvox does not get updated when I change the string wich the textbox is...
0
by: Patrick B | last post by:
I'm wondering about the mechanics of databinding. Say that a textbox is bound to a property of a business object. The business object is a "Person". The control is a textbox called...
2
by: Colin Robinson | last post by:
Help please I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the Person.Firstname property Can...
3
by: virlinz | last post by:
Hello I'm a newbie who has a problem with updating the dataset into the database. Maybe I missed a few lines of codes. Please shed some light for me. The following code is working but not like I...
2
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry...
7
by: Naveen | last post by:
I posted this message to another board and have hardly had any views on it, leave alone answers. So I am cross-posting here. This may be a very simple question but I can't get my head around it....
11
by: =?Utf-8?B?R29rdWw=?= | last post by:
I am struck up with a problem and want anyone here to help me out. I am a beginner in .NET trying to learng DataBinding concepts. I have binded 4 text boxes with a dataset but when I say...
3
by: Peter | last post by:
Hi! I am having some very strange behavior with my databound controls. It's taken a long time to isolate exactly what is provoking the problem, but I'm still leagues away from solving it. I...
0
by: nelsonbrodyk | last post by:
Hey All, I have been able to set up a databinding to a property with the following code: <TextBox x:Name="txtTextBox" Text="{Binding Path=NameFirst, Mode=TwoWay,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.