Microsoft KB Archive/829615

= FIX: Overlapping forms with a DataGrid control automatically come to the foreground when the data source is updated in the .NET Framework 1.1 =

Article ID: 829615

Article Last Modified on 5/21/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1

-





SYMPTOMS
When you run a Microsoft Windows application that contains two overlapping Windows forms, the forms automatically come to the foreground. This problem occurs when the overlapping forms contain a DataGrid control. This problem occurs every time that the data source of the DataGrid control is updated.



RESOLUTION
To resolve this problem, obtain the latest service pack for the Microsoft .NET Framework 1.1.

The following file is available for download from the Microsoft Download Center:

The Microsoft .NET Framework 1.1 Service Pack 1

http://www.microsoft.com/downloads/details.aspx?FamilyId=A8F5654F-088E-40B2-BBDB-A83353618B38



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section. This problem was first corrected in the Microsoft .NET Framework 1.1 Service Pack 1.



Steps to reproduce the problem
 Start Microsoft Visual Studio .NET 2003. Or, start Microsoft Visual C# .NET 2003. Create a Windows application that is named MyApp by using Microsoft Visual Basic .NET 2003.

By default, a file that is named Form1.vb is created.

Alternatively, create a Windows application that is named MyApp by using Visual C# .NET 2003.

By default, a file that is named Form1.cs is created. Add a DataGrid control, a CheckBox control, a Button control, and a Timer component to the Form1 form. Right-click the Timer component, and then click Properties. In the Properties window, set the Interval property to 3000. In Solution Explorer, right-click Form1.vb, and then click View Code.</li>  Add the following code to the Declarations section of the Form1 class:

Visual Basic .NET code Dim dt As DataTable Visual C# .NET code private DataTable dt; </li>  In Design view, double-click the Form1 form, and then add the following code to the Form1_Load procedure:

Visual Basic .NET code dt = New DataTable 'Add columns to the data table. dt.Columns.Add(&quot;Name&quot;) dt.Columns.Add(&quot;Description&quot;) DataGrid1.DataSource = dt 'Add rows to the data table. Dim row1 As DataRow = dt.NewRow Dim row2 As DataRow = dt.NewRow Dim row3 As DataRow = dt.NewRow row1(&quot;Name&quot;) = &quot;1&quot; row1(&quot;Description&quot;) = &quot;This is a test application.&quot; dt.Rows.Add(row1) row2(&quot;Name&quot;) = &quot;2&quot; row2(&quot;Description&quot;) = &quot;This is a test application.&quot; dt.Rows.Add(row2) row3(&quot;Name&quot;) = &quot;3&quot; row3(&quot;Description&quot;) = &quot;This is a test application.&quot; dt.Rows.Add(row3) Visual C# .NET code dt = new DataTable; //Add columns to the data table. dt.Columns.Add(&quot;Name&quot;); dt.Columns[&quot;Name&quot;].DataType =System.Type.GetType(&quot;System.Int32&quot;); dt.Columns.Add(&quot;Description&quot;); dataGrid1.DataSource = dt; //Add rows to the data table. DataRow row1= dt.NewRow; row1[&quot;Name&quot;] = &quot;1&quot;; row1[&quot;Description&quot;] = &quot;This is a test application.&quot;; dt.Rows.Add(row1); DataRow row2=dt.NewRow; row2[&quot;Name&quot;] = &quot;2&quot;; row2[&quot;Description&quot;] = &quot;This is a test application.&quot;; dt.Rows.Add(row2); DataRow row3=dt.NewRow; row3[&quot;Name&quot;] = &quot;3&quot;; row3[&quot;Description&quot;] = &quot;This is a test application.&quot;; dt.Rows.Add(row3); </li>  In Design view of the Form1 form, double-click Button1, and then add the following code to the Button1_Click procedure:

Visual Basic .NET code Me.Button1.Visible = False 'Create an instance of the Form1 form. Dim f1 As New Form1 f1.Text = &quot;Form2&quot; f1.Show f1.Button1.Visible = False

Visual C# .NET code this.button1.Visible =false; //Create an instance of the Form1 form. Form1 f1 = new Form1; f1.Text = &quot;Form2&quot;; f1.Show; f1.button1.Visible =false; </li>  In Design view of the Form1 form, double-click Timer1, and then add the following code to the Timer1_Tick procedure:

Visual Basic .NET code Dim row As DataRow For Each row In dt.Rows Row(0) = dt.Rows(0)(0) * 2 Next Visual C# .NET code foreach(DataRow row in dt.Rows) {    row[0] = (int)dt.Rows[0][0] * 2; } </li>  In Design view of the Form1 form, double-click CheckBox1, and then add the following code to the CheckBox1_CheckedChanged procedure:

Visual Basic .NET code If CheckBox1.Checked = True Then Timer1.Enabled = True Else Timer1.Enabled = False End If Visual C# .NET code if (checkBox1.Checked == true) timer1.Enabled = true; else timer1.Enabled = false; </li> On the Build menu, click Build Solution.</li> On the Debug menu, click Start.

The Form1 form appears.</li> Click Button1.

The Form2 form appears. Position the forms so that the forms overlap.</li> Click the Name column in the DataGrid control on the Form1 form and on the Form2 form.

This sorts the DataGrid control on the Name column.</li> Click to select the CheckBox1 check box on the Form1 form and on the Form2 form.

This enables the Timer component.

After several seconds, you notice that the overlapping forms automatically come to the foreground. This problem occurs every time that you update the Name column in the DataGrid control.

Note This problem occurs only when the forms overlap.</li></ol>

<div class="references_section">