Microsoft KB Archive/825031

= FIX: You may receive an &quot;IndexOutOfRangeException&quot; error message when you use the SHIFT+UP ARROW key combination in a DataGrid control in Visual Studio .NET 2002 =

Article ID: 825031

Article Last Modified on 2/21/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.0 Service Pack 2
 * Microsoft .NET Framework 1.0 Service Pack 1
 * 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 &quot;Applies to&quot; section. This problem was first corrected in the Microsoft .NET Framework 1.0 Service Pack 3.



Steps to reproduce the problem
 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project.

The New Project dialog box appears. Under Project Types, click Visual Basic Projects. Under Templates, click Windows Application. In the Name box, type WindowsApplication1 as the name of the application. 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.</li> 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.</li>  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(&quot;TABLE&quot;)

Dim col As New DataColumn col.DataType = Type.GetType(&quot;System.String&quot;) col.ColumnName = &quot;col1&quot; col.DefaultValue = &quot;000&quot; 'Add columns. dataTable.Columns.Add(New DataColumn(&quot;Col1&quot;)) dataTable.Columns.Add(New DataColumn(&quot;Col2&quot;)) dataTable.Columns.Add(New DataColumn(&quot;Col3&quot;))

Dim myDataRow As DataRow = dataTable.NewRow myDataRow(0) = &quot;11111&quot; myDataRow(1) = &quot;22222&quot; myDataRow(2) = &quot;33333&quot; dataTable.Rows.Add(myDataRow)

DataGrid1.DataSource = dataTable.DefaultView

Visual C# .NET code DataTable dataTable; dataTable = new DataTable(&quot;TABLE&quot;);

DataColumn col = new DataColumn; col.DataType = Type.GetType(&quot;System.String&quot;); col.ColumnName = &quot;col1&quot;; col.DefaultValue = &quot;000&quot;; //Add columns. dataTable.Columns.Add(new DataColumn(&quot;Col1&quot;)); dataTable.Columns.Add(new DataColumn(&quot;Col2&quot;)); dataTable.Columns.Add(new DataColumn(&quot;Col3&quot;));

DataRow myDataRow = dataTable.NewRow; myDataRow[0] = &quot;11111&quot;; myDataRow[1] = &quot;22222&quot;; myDataRow[2] = &quot;33333&quot;; dataTable.Rows.Add(myDataRow);

dataGrid1.DataSource = dataTable.DefaultView; </li> On the Build menu, click Build Solution.</li> On the Debug menu, click Start.

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

You may receive the error message that is mentioned in the &quot;Symptoms&quot; section.</li></ol>

<div class="references_section">