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 translations Article translations
Article ID: 829615 - View products that this article applies to.
Expand all | Collapse all

On This Page

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 "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

  1. Start Microsoft Visual Studio .NET 2003. Or, start Microsoft Visual C# .NET 2003.
  2. 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.
  3. Add a DataGrid control, a CheckBox control, a Button control, and a Timer component to the Form1 form.
  4. Right-click the Timer component, and then click Properties.
  5. In the Properties window, set the Interval property to 3000.
  6. In Solution Explorer, right-click Form1.vb, and then click View Code.
  7. 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;
  8. 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);
  9. 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;
  10. 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;
    }
      
  11. 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;
  12. On the Build menu, click Build Solution.
  13. On the Debug menu, click Start.

    The Form1 form appears.
  14. Click Button1.

    The Form2 form appears. Position the forms so that the forms overlap.
  15. 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.
  16. 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
http://msdn2.microsoft.com/en-us/library/aa983652(VS.71).aspx
DataGrid control (Windows forms)
http://msdn2.microsoft.com/en-us/library/aa983595(VS.71).aspx

Properties

Article ID: 829615 - Last Review: May 21, 2007 - Revision: 2.2
APPLIES TO
  • Microsoft .NET Framework 1.1
Keywords: 
kbqfe kbhotfixserver kbwindowsforms kbcontrol kbdatabinding kbdisplay kbnetframe110sp1fix kbnetframe110presp1fix kbfix kbbug KB829615

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com