473,386 Members | 1,606 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.

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
Nov 20 '05 #1
10 1123
Hi Marina,

Better is to stay in the same thread as you know, however see my message in
the original thread.

Cor
Nov 20 '05 #2
I posted a new thread, so that if people lost interest in the old one, they
would see the restated version.

You are right, your example does work.

The question is: why?

If I did the same thing, except had 2 textboxes, added a binding for each of
them for their Text property, and used just the datatable - all would work
great.

It only starts breaking when Text and non-Text properties are mixed - and I
want to know why. If it's 2 Text properties, everything is well. And if it
is a Text property and some other property - then changing the non-Text
property works as expected - it is only when doing the same with a Text
property that it breaks.

So why work one way and not the other (like in my original example)?

The issue being is that I'm working on something very generic that would
allow people to have controls on a form bound to any column - possibly some
columns being bound to by more then one control.

If I need to start creating a separate dataview for each time I add a
databinding, I can only imagine the performance hit, not to mention the
management issue.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ub**************@TK2MSFTNGP09.phx.gbl...
Hi Marina,

Better is to stay in the same thread as you know, however see my message in the original thread.

Cor

Nov 20 '05 #3
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
///
Nov 20 '05 #4
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
///

Nov 20 '05 #5
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
///

Nov 20 '05 #6
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?

Nov 20 '05 #7
That was the change what I did as well so read my text again.
Nov 20 '05 #8
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
Nov 20 '05 #9
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.

Nov 20 '05 #10
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

Nov 20 '05 #11

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

Similar topics

9
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. ...
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...
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: 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: 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.