BUG on BindingContext in framework V1.1

  • Thread starter ABC - Sébastien Beaugrand
  • Start date
A

ABC - Sébastien Beaugrand

Hi,

I've been trying to get an answer from french newsgroup but I did'nt succeed
in this, so I'll try on this group and sorry for my poor english.

The description of the bug :

The CurrentChanged event from the BindinManager on a Winform never occurs
with framework V1.1. and it is not possible from the bindings to know if
the user has done some modifications.

With framework V1.0 it was OK

You can find after a sample to reproduce this bug. You just have to play
this a first time with framework 1.0 to see that if you change anything in
the form you got a messagebox.

If you set the framework to V1.1 in your project and play it, you'll notice
that the event is not raised by the framework.
The project is made of a simple form (form1) with 2 textbox for displayiong
data. It is running on Pubs database from SQL Server running on local.

I would like to know if this bug is known from Microsoft Team and if a Patch
exists for this or is planned ?

Thank you,
Sebastien


'*************** CODE SAMPLE FORM FORM1
****************************************************
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
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
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(40, 16)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(40, 40)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Dim WithEvents MyBindingManager As BindingManagerBase
Dim ds As New DataSet
Dim dt As New DataTable
Private Sub MyBindingManager_CurrentChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles MyBindingManager.CurrentChanged
MsgBox("Modification des données")
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim CNX As String
Dim ds As DataSet
CNX = "Integrated Security=SSPI;Initial Catalog=Pubs;Data Source=127.0.0.1"
ds = ExecuteSQL("select top 10 * from authors", CNX, , True)
dt = ds.Tables(0)
Me.TextBox1.DataBindings.Clear()
Me.TextBox1.DataBindings.Add("Text", dt, "au_fname")
Me.TextBox2.DataBindings.Clear()
Me.TextBox2.DataBindings.Add("Text", dt, "au_lname")
MyBindingManager = Me.BindingContext.Item(dt)
End Sub
Public Function ExecuteSQL(ByVal sSql As String, ByVal ConnectionString As
String, Optional ByVal TimeOut As Integer = 30, Optional ByVal
DisplayErrorMessages As Boolean = False) As Data.DataSet
Dim Conn As SqlConnection
Dim selectCMD As SqlCommand
Dim da As SqlDataAdapter
Dim ds As Data.DataSet
Try
Conn = New SqlConnection(ConnectionString)
selectCMD = New SqlCommand(sSql, Conn)
selectCMD.CommandTimeout = TimeOut
da = New SqlDataAdapter
da.SelectCommand = selectCMD
Conn.Open()
ds = New DataSet
da.Fill(ds, "ROWSET")
Conn.Close()
Catch
If DisplayErrorMessages = True Then
Call MsgBox("Err : " & Err.Number & vbCrLf & "Description : " &
Err.Description, MsgBoxStyle.Critical, "Erreur d'accès aux données")
End If
End Try
Return ds
End Function
End Class
'*************** END OF CODE OF FORM1
*****************************************
 
C

CJ Taylor

Try using a CurrencyManager instead of BindingManagerBase...

I have no clue if it would work, but I have had currentchanged fire on
currencymanager before in 1.1

-CJ
 
A

ABC - Sébastien Beaugrand

Hi,

It's true that it fires when position changes but not when the content of
the text box changes.
I am using this event with FWK1.0 to know if the user had changed anything
in the record so I can ask him if he wants to save his changes.

I'll go to see the link you give me.
Thanks
 
C

CJ Taylor

Your hooking the wrong event.. don't hook to the currecny manager, but to
the underlying row of data (from a dataset or whatever) you are binding to.

For a dataset, you would want to hook the columnchanged or rowchanged events
of a row...
 
C

Cor Ligthert

Hi CJ,

I did ask something to you can you translate it for us.

It seems that in 1.0 as sebastian stated the event fired when the user
clicked something in the textbox the same as the textbox.textchanged event.

The text from msdn for me sounds also like that, however you can probably
tell that better than us no English EU persons.

"Occurs when the bound value changes".

Cor
 
C

CJ Taylor

Cor,

Yeah I know I read that too, but just from my own experiences it doesn't
always fire, or fires way too often. In most cases I only got it to fire
when I changed rows on the binding context and rarely if I changed a value
(it seemed to be almost dependent on length on the validating event. which
is when it is *supposed* to fire. Or at least when I think it should. )

This is just my experience with it.. Like I said, I deal with Datasets a lot
so I attach to the column changing/changed event and that works better than
binding context as far as I'm concerned.
 
A

ABC - Sébastien Beaugrand

It was exactly what I wanted the BindingManager to do : "Occurs when the
bound value changes"

It was doing the job with Framework 1.0 but now with 1.1 it is not working.
That's why I'm talking about a bug.

Of course It is possible to do that with record changing event, but in this
context the application is working in production since more than one year on
many computers. It is not possible to change that code at low price, and
because of this bug it's not possible to migrate the application from VSNET
2002 to VSNET 2003...

That's why I am waiting for a patch.
 
P

Peter Huang

Hi,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that when you use the BindingContext of
Textbox, the currentchanged event will not be fired in VS.NET 2003.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think we may workaround the issue by using the code similar with below.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.OleDbDataAdapter1.Fill(Me.DataSet11)
Me.TextBox1.DataBindings.Add("Text", DataSet11.Employees, "Address")
Dim o As Object = Environment.Version()
Dim bmb As BindingManagerBase
If o.ToString() = "1.1.4322.573" Then
bmb = BindingContext(DataSet11.Employees, "Address")
ElseIf o.ToString() = "1.0.3705.0" Then
bmb = BindingContext(DataSet11.Employees)
End If
AddHandler bmb.CurrentChanged, AddressOf cm_CurrentChanged
End Sub
Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
'Change the focus from textbox1 to textbox2 will fire the event
MsgBox("cm_CurrentChanged")
End Sub

Please apply my suggestion above and let me know if it helps resolve your
problem.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

CJ Taylor

Fair enough. I never really noticed it from 1.0 to 1.1, my own fault I
suppose. Peter's suggestion looks intersting, hope it works out, let us
know.

-CJ
 
C

Cor Ligthert

Hi CJ,

As far as I can see gives this a current changed, for that are more options,
as I understand Sebastian wants an event when the value from the binded
textboxes change. (Something that in my opinion would fire enormous often)

Cor
 

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