FIX: You may receive an "IndexOutOfRangeException" error message when you use the SHIFT+UP ARROW key combination in a DataGrid control in Visual Studio .NET 2002 (825031)



The information in this article applies to:

  • Microsoft .NET Framework 1.0 SP2
  • Microsoft .NET Framework 1.0 SP1
  • Microsoft .NET Framework 1.0

SYMPTOMS

When you use the SHIFT+UP ARROW key combination in a DataGrid control, a problem may occur. When this problem occurs, you also have the ReadOnly property of the DataGrid control set to true. You also have all the rows in the DataGrid control selected.

You may receive the following error message:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Windows.Forms.DataGrid.ProcessGridKey(KeyEventArgs ke)
at System.Windows.Forms.DataGrid.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.ThreadContext.System.Windows.Forms.
UnsafeNativeMethods+IMsoComponent.FPreTranslateMessage(MSG& msg)

RESOLUTION

To resolve this problem, obtain the latest service pack for the Microsoft .NET Framework 1.0. The following file is available for download from the Microsoft Download Center:

The Microsoft .NET Framework 1.0 Service Pack 3

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.0 Service Pack 3.

MORE INFORMATION

Steps to reproduce the problem

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.

    The New Project dialog box appears.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Windows Application.
  5. In the Name box, type WindowsApplication1 as the name of the application.
  6. Click OK.

    By default, a file that is named Form1.vb is added to the project if you are using Visual Basic .NET.

    By default, a file that is named Form1.cs is added to the project if you are using Microsoft Visual C# .NET.
  7. Double-click DataGrid to add a DataGrid control to the form that is named Form1.

    By default, the DataGrid control that is named DataGrid is added to the form that is named Form1.
  8. In Design view of Form1, double-click the form that is named Form1, and then add the following code to the Form1_Load procedure:

    Visual Basic .NET code
    Dim dataTable As DataTable
    dataTable = New DataTable("TABLE")
    
    Dim col As New DataColumn()
    col.DataType = Type.GetType("System.String")
    col.ColumnName = "col1"
    col.DefaultValue = "000"
    'Add columns.  
    dataTable.Columns.Add(New DataColumn("Col1"))
    dataTable.Columns.Add(New DataColumn("Col2"))
    dataTable.Columns.Add(New DataColumn("Col3"))
    
    Dim myDataRow As DataRow = dataTable.NewRow()
    myDataRow(0) = "11111"
    myDataRow(1) = "22222"
    myDataRow(2) = "33333"
    dataTable.Rows.Add(myDataRow)
    
    DataGrid1.DataSource = dataTable.DefaultView

    Visual C# .NET code
    DataTable dataTable;
    dataTable = new DataTable("TABLE");
    
    DataColumn col = new DataColumn();
    col.DataType = Type.GetType("System.String");
    col.ColumnName = "col1";
    col.DefaultValue = "000";
    //Add columns.  
    dataTable.Columns.Add(new DataColumn("Col1"));
    dataTable.Columns.Add(new DataColumn("Col2"));
    dataTable.Columns.Add(new DataColumn("Col3"));
    
    DataRow myDataRow = dataTable.NewRow();
    myDataRow[0] = "11111";
    myDataRow[1] = "22222";
    myDataRow[2] = "33333";
    dataTable.Rows.Add(myDataRow);
    
    dataGrid1.DataSource = dataTable.DefaultView;
  9. On the Build menu, click Build Solution.
  10. On the Debug menu, click Start.

    The form that is named Form1 appears.
  11. Put the pointer in any column of the last row in the DataGrid control.
  12. Select all the cells in the DataGrid control by using the CTRL+A key combination.
  13. Press the SHIFT+UP ARROW key combination.

    You may receive the error message that is mentioned in the "Symptoms" section.

REFERENCES

For additional information, visit the following Microsoft Developer Network (MSDN) Web site:

The Windows Forms DataGrid For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

320584 How to trap keystrokes in .NET controls by using Visual C# .NET


Modification Type:MajorLast Reviewed:8/30/2004
Keywords:kbNetFrame100preSP3fix kbCtrl kbControl kbQFE kbfix kbbug KB825031 kbAudDeveloper