472,364 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Binding problem restated - inconsistent behavior in databinding

Here is the problem. If 2 different properties on the same (or different)
control are bound to the same data column, changing the Text property and
calling EndCurrentEdit discards the new value. Changing a custom property
and calling EndCurrentEdit accepts the new value, stores it in the datasoure
and behaves normally. Here is a reproduceable example:

First, extend Textbox:

Public Class MyTextBox
Inherits TextBox

Private myProp As String

Public Property MyProperty() As String
Get
Return myProp
End Get
Set(ByVal Value As String)
myProp = Value
End Set
End Property
End Class

Then, use this new Textbox on a form, and run this example.

You will notice, that calling just TestCustomProperty, updates the value in
the datasource and in what is displayed in the textbox.
Calling just TestTextProperty discards the value and does not update
anything.

What I want to understand is - why the behavior difference?

Note, I have experimented, and binding to the Text properties of 2 different
textboxes works fine.
This is only a problem in binding to the Text property and another property.
There is something about the Text property that seems to make it behave very
strangely when the column it is bound to, is also bound to another non-Text
property.

Here is the Form code:

Public Class Form2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MyTextBox1 As VisionControlTester.MyTextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.MyTextBox1 = New VisionControlTester.MyTextBox
Me.SuspendLayout()
'
'MyTextBox1
'
Me.MyTextBox1.Location = New System.Drawing.Point(80, 72)
Me.MyTextBox1.MyProperty = Nothing
Me.MyTextBox1.Name = "MyTextBox1"
Me.MyTextBox1.TabIndex = 0
Me.MyTextBox1.Text = "MyTextBox1"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.MyTextBox1)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)

End Sub

#End Region
Dim dt As New DataTable

Private Sub Form2_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dt.Columns.Add("MyColumn")
Dim row As DataRow = dt.NewRow
row(0) = "TestValue"
dt.Rows.Add(row)

MyTextBox1.DataBindings.Add("Text", dt, "MyColumn")
MyTextBox1.DataBindings.Add("MyProperty", dt, "MyColumn")

TestTextProperty()

TestCustomProperty()
End Sub

Private Sub TestTextProperty()
MyTextBox1.Text = "NewValue"
Me.BindingContext(dt).EndCurrentEdit()
End Sub

Private Sub TestCustomProperty()
MyTextBox1.MyProperty = "NewValue"
Me.BindingContext(dt).EndCurrentEdit()
End Sub
End Class
Jul 21 '05 #1
9 1631
Hi Marina,
There is something strange this message was not in the lanuage.vb group,
however I have placed an answer there.

Cor
Jul 21 '05 #2
Hi Marina,

This you do not believe, I was thinking maybe is there something in the
logic that it keeps the value from the binding and uses that.

To test that I changed the code to this.

And you may tell me what happens here, however I think you can use it.

For me it is something the same as that text from the combobox where I want
to use the text part real as a textbox.

Cor

\\\
Dim dt As New DataTable
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("MyColumn")
Dim row As DataRow = dt.NewRow
row(0) = "TestValue"
dt.Rows.Add(row)
MyTextBox1.DataBindings.Add("MyProperty", dt, "MyColumn")
MyTextBox1.DataBindings.Add("Text", dt, "MyColumn")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MyTextBox1.Text = "TextValue"
Me.BindingContext(dt).EndCurrentEdit()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
MyTextBox1.MyProperty = "PropValue"
Me.BindingContext(dt).EndCurrentEdit()
End Sub
End Class
///
Jul 21 '05 #3
I'm not sure what you mean. Nothing happens when I run code like this -
clicking Button1 doesn't accept the value, just as it didn't in my previous
code. Clicking Button2 does accept the value. So the behavior is the same as
before.

Again, I am still confused as to why the matching of Text and non-Text
properties is causing the behavior. Also, why it is inconsistently behaving
this way - i.e. changing the non-Text property accepts the value - changing
the Text property does not. Why?

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uZ****************@tk2msftngp13.phx.gbl...
Hi Marina,

This you do not believe, I was thinking maybe is there something in the
logic that it keeps the value from the binding and uses that.

To test that I changed the code to this.

And you may tell me what happens here, however I think you can use it.

For me it is something the same as that text from the combobox where I want to use the text part real as a textbox.

Cor

\\\
Dim dt As New DataTable
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("MyColumn")
Dim row As DataRow = dt.NewRow
row(0) = "TestValue"
dt.Rows.Add(row)
MyTextBox1.DataBindings.Add("MyProperty", dt, "MyColumn")
MyTextBox1.DataBindings.Add("Text", dt, "MyColumn")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MyTextBox1.Text = "TextValue"
Me.BindingContext(dt).EndCurrentEdit()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
MyTextBox1.MyProperty = "PropValue"
Me.BindingContext(dt).EndCurrentEdit()
End Sub
End Class
///

Jul 21 '05 #4
Here is another weird thing. If you reverse the order of the addition of
the bindings - then everything works perfectly! So add binding for
MyProperty first, then for Text

Both changing MyProperty or Text now start working as they should!

What is up with that?

Why does the order matter?
Is this a bug? It's hard to imagine someone designing this kind of behavior
on purpose!

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uZ****************@tk2msftngp13.phx.gbl...
Hi Marina,

This you do not believe, I was thinking maybe is there something in the
logic that it keeps the value from the binding and uses that.

To test that I changed the code to this.

And you may tell me what happens here, however I think you can use it.

For me it is something the same as that text from the combobox where I want to use the text part real as a textbox.

Cor

\\\
Dim dt As New DataTable
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("MyColumn")
Dim row As DataRow = dt.NewRow
row(0) = "TestValue"
dt.Rows.Add(row)
MyTextBox1.DataBindings.Add("MyProperty", dt, "MyColumn")
MyTextBox1.DataBindings.Add("Text", dt, "MyColumn")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MyTextBox1.Text = "TextValue"
Me.BindingContext(dt).EndCurrentEdit()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
MyTextBox1.MyProperty = "PropValue"
Me.BindingContext(dt).EndCurrentEdit()
End Sub
End Class
///

Jul 21 '05 #5
Hi Marina,

With me gives button 1 with this code textValue and button2
Propvalue and I can go on and on, are you sure you changed those two
bindings from place?.

Cor
I'm not sure what you mean. Nothing happens when I run code like this -
clicking Button1 doesn't accept the value, just as it didn't in my previous code. Clicking Button2 does accept the value. So the behavior is the same as before.

Again, I am still confused as to why the matching of Text and non-Text
properties is causing the behavior. Also, why it is inconsistently behaving this way - i.e. changing the non-Text property accepts the value - changing the Text property does not. Why?

Jul 21 '05 #6
That was the change what I did as well so read my text again.
Jul 21 '05 #7
Hi Marina,

What is posible is that the binding from the properties is in a sequential
way.

Something the same as when you do a classic byte move than you get this kind
of behaviour.

I do not know if you no that. You copy a byte over the next byte which copys
again with the new value. I don't know if it is still used but a classic way
to set all bytes to zero.

That can be the same behaviour as this. However just a gues.

Cor
Jul 21 '05 #8
Oh, I see, I didn't notice, sorry.

Does that not seem odd that bindings have to be done in some order? I mean,
one would think that the order wouldn't matter - or at least it shouldn't. I
would expect the same behavior no matter the order.

I mean, Text is just another property. And it's fine if the other properties
bound to that column are other Text properties belonging to different
controls.

Do you or anyone else know why the order matters? Is there any
documentation explaining this? Is this expected behavior? If it is expected,
there certainly should be documentation defining it - otherwise, how is one
supposed to know the order to add these bindings in?
Is there an explanation of

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uP*************@tk2msftngp13.phx.gbl...
That was the change what I did as well so read my text again.

Jul 21 '05 #9
I would accept that order matters, if reversing the order of the bindings
broke TestCustomProperty.

The problem is: it doesn't. If TestCustomProperty would stop working - at
least behavior would be consistent. But it works fine - just as
TestTextProperty begins working as it should.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi Marina,

What is posible is that the binding from the properties is in a sequential
way.

Something the same as when you do a classic byte move than you get this kind of behaviour.

I do not know if you no that. You copy a byte over the next byte which copys again with the new value. I don't know if it is still used but a classic way to set all bytes to zero.

That can be the same behaviour as this. However just a gues.

Cor

Jul 21 '05 #10

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

Similar topics

9
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be...
10
by: Marina | last post by:
Here is the problem. If 2 different properties on the same (or different) control are bound to the same data column, changing the Text property and calling EndCurrentEdit discards the new value. ...
11
by: Rourke Eleven | last post by:
I have looked and searched. What good is the databind property on Radiobuttons? How does one go about actually using it? What is a good resource on this? I understand that I can easily get/set...
0
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having...
3
by: Tim Baur | last post by:
I'm a VB6 developer who's just beginning to make the move to .Net 2005, and I'm wondering if data binding is worth the effort. After a lot of fighting with it in VB6, I finally realized the best...
3
by: Wilson | last post by:
Hi, Can I do data binding for a textbox in a webform at server side ? not using the Data Binding Expression. Thanks Wilson
3
by: Peter | last post by:
OK, so in addition to the problem I mentioned before (c.f. "Data Binding to Textbox"), I realized that my comboboxes are not really bound to the internal data set. They are just set to manually...
1
by: Stephen Barrett | last post by:
I have an application that was originally built with ASP.Net 1.1. We finally got permission to migrate to 2.0. Due to time constraints we migrated the web projects to 2.0 web application...
6
by: Dmitry Duginov | last post by:
Hi, I have the following label markup (label is inside FormView): <asp:Label ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready" BackColor='<%#...
6
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

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.