M
Marina
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
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