Microsoft KB Archive/317254

= FIX: Cannot close form when the Tag property is bound to a read-only field =

Article ID: 317254

Article Last Modified on 9/15/2005

-

APPLIES TO


 * Microsoft .NET Framework 1.1 Service Pack 1
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-



This article was previously published under Q317254



SYMPTOMS
If the Tag property of a Windows Forms control is bound to a read-only field in a DataSet object, you cannot move the focus away from the control, and you cannot close the form.



CAUSE
Because the Tag property does not cause a change notification, an attempt is always made to update the underlying DataTable class. This does not occur with the Text property because the TextChanged event is fired, and a check is made to see if the property was updated.



RESOLUTION
To work around this problem, handle the Parse event for the data-bound property, and then throw an exception. This exception is caught at a lower level and is not seen. The exception does not interfere with other data binding on the form.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft ADO.NET (included with the .NET Framework 1.1), and Microsoft Visual Studio .NET (2003).



Steps to Reproduce the Behavior
 Start Visual Studio .NET, and then create a new Microsoft Visual Basic .NET Windows application. Drag a SqlDataAdapter object from the Data tab of the toolbox to the form.  Use the wizard to set up a connection to the Northwind database on the computer that is running Microsoft SQL Server. Use the following SQL statement to fetch the data: SELECT EmployeeID, LastName, FirstName FROM Employees  Right-click SqlDataAdapter1, and then click Generate Dataset. Click OK to add DataSet11 to the designer. Drag a TextBox control from the toolbox to the form.</li> In the Properties window, expand (DataBindings), and then bind the Tag property to EmployeeID.</li>  To fill the DataSet, add the following code to the Form1_Load event: SqlDataAdapter1.Fill(DataSet11) </li> Drag a second TextBox control from the toolbox to the form.</li> Press F5 to run the application. Notice that you cannot close the form and that you cannot tab out of TextBox1. However, notice that the Minimize and the Maximize buttons work.</li>  To work around this problem, return to the Visual Studio IDE, stop debugging, and then modify your code as follows: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler TextBox1.DataBindings(&quot;tag&quot;).Parse, AddressOf parseit SqlDataAdapter1.Fill(DataSet11) End Sub

Sub parseit(ByVal o As Object, ByVal e As ConvertEventArgs) Throw New Exception End Sub </li> Run the application again. Notice that you can tab out of TextBox1 and that you can close the form.</li></ol>

Additional query words: readonly tag binding databound

Keywords: kbbug kbfix kbnofix kbdatabinding kbvs2002sp1sweep KB317254

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.