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
STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in the Microsoft .NET Framework 1.1 Service Pack 1.
MORE INFORMATION
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.
Add the following code to the Declarations section of the Form1 class:
Visual Basic .NET codeDim dt As DataTable
Visual C# .NET code
private DataTable dt;
In Design view, double-click the Form1 form, and then add the following code to the Form1_Load procedure:
Visual Basic .NET codedt = New DataTable 'Add columns to the data table. dt.Columns.Add("Name") dt.Columns.Add("Description") 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("Name") = "1" row1("Description") = "This is a test application." dt.Rows.Add(row1) row2("Name") = "2" row2("Description") = "This is a test application." dt.Rows.Add(row2) row3("Name") = "3" row3("Description") = "This is a test application." dt.Rows.Add(row3)
Visual C# .NET code
dt = new DataTable(); //Add columns to the data table. dt.Columns.Add("Name"); dt.Columns["Name"].DataType =System.Type.GetType("System.Int32"); dt.Columns.Add("Description"); dataGrid1.DataSource = dt; //Add rows to the data table. DataRow row1= dt.NewRow(); row1["Name"] = "1"; row1["Description"] = "This is a test application."; dt.Rows.Add(row1); DataRow row2=dt.NewRow(); row2["Name"] = "2"; row2["Description"] = "This is a test application."; dt.Rows.Add(row2); DataRow row3=dt.NewRow(); row3["Name"] = "3"; row3["Description"] = "This is a test application."; dt.Rows.Add(row3);
In Design view of the Form1 form, double-click Button1, and then add the following code to the Button1_Click procedure:
Visual Basic .NET codeMe.Button1.Visible = False 'Create an instance of the Form1 form. Dim f1 As New Form1 f1.Text = "Form2" f1.Show() f1.Button1.Visible = False
Visual C# .NET codethis.button1.Visible =false; //Create an instance of the Form1 form. Form1 f1 = new Form1(); f1.Text = "Form2"; f1.Show(); f1.button1.Visible =false;
In Design view of the Form1 form, double-click Timer1, and then add the following code to the Timer1_Tick procedure:
Visual Basic .NET codeDim 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; }
In Design view of the Form1 form, double-click CheckBox1, and then add the following code to the CheckBox1_CheckedChanged procedure:
Visual Basic .NET codeIf 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;
- On the Build menu, click Build Solution.
- On the Debug menu, click Start.
The Form1 form appears. - Click Button1.
The Form2 form appears. Position the forms so that the forms overlap. - 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. - 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.
REFERENCES
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
824684 Description of the standard terminology that is used to describe Microsoft software updates
For additional information, visit the following Microsoft Developer Network (MSDN) Web sites:
Introduction to the Windows forms DataGrid control
DataGrid control (Windows forms)
Keywords: kbqfe kbhotfixserver kbwindowsforms kbcontrol kbdatabinding kbdisplay kbnetframe110sp1fix kbnetframe110presp1fix kbfix kbbug KB829615