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.
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.
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 code
Dim 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 code
dt = 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 code
Me.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 code
this.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 code
Dim row As DataRow
For Each row In dt.Rows
Row(0) = dt.Rows(0)(0) * 2
Next
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.