Microsoft KB Archive/819345

= BUG: Error message when you set the Width property of a Boolean DataGrid column to 1 in Visual Basic .NET or in Visual C# .NET: &quot;System.ArgumentException&quot; =

Article ID: 819345

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-



SYMPTOMS
You bind a DataGrid control to a data source that has a column with Boolean data. If you set the Width property of the DataGrid Boolean column to 1 at run time, you receive the following exception:

An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

Additional information: Invalid parameter used.



WORKAROUND
To work around this bug, do not set the Width property of the DataGrid Boolean column to 1.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 In Microsoft Visual Studio .NET, start a new Windows application by using Microsoft Visual Basic .NET or Microsoft Visual C# .NET.

By default, Form1 is created. On the View menu, click Server Explorer. Right-click Data Connections, and then click Add Connection. Click the Connection tab, type your local Microsoft SQL Server name in the Select or enter a server name box, and then click to select Northwind. On the toolbox, click the Data tab. Drag SqlDataAdapter to Form1.</li> In the Data Adapter Configuration Wizard panel, click Next three times.</li>  In the Generate the SQL statements panel, enter the following code, and then click Next: select Productid,Discontinued from Products </li> Click Finish to close the Data Adapter Configuration Wizard panel.</li> Right-click SqlDataAdapter1, and then click Generate Dataset.

By default, DataSet11 is created.</li> Drag a DataGrid control from the toolbox to Form1.</li> Right-click DataGrid1, and then click Properties.</li> In the Properties window, set the DataSource to DataSet11, and then set the DataMember property to Products.</li>  Add the following code to the Form1 Load event:

Visual Basic .NET Code Dim t As DataTable t = DataSet11.Tables(0) 'DataGridTableStyle controls the appearance of the grid for a table. Dim myGridTableStyle As DataGridTableStyle = New DataGridTableStyle 'Maps to the Products table. myGridTableStyle.MappingName = t.TableName 'Add the myGridTableStyle to the TableStyles Collection of DataGrid. DataGrid1.TableStyles.Add(myGridTableStyle) 'Set the width of the Boolean Column &quot;DisContinued&quot; to 1. myGridTableStyle.GridColumnStyles(&quot;Discontinued&quot;).Width = 1 Visual C# .NET Code //DataGridTableStyle controls the appearance of the grid for a table. DataTable t= dataSet11.Tables[0]; DataGridTableStyle myGridTableStyle = new DataGridTableStyle; //Maps to the Products table. myGridTableStyle.MappingName = t.TableName; //Add the myGridTableStyle to the TableStyles Collection of DataGrid. dataGrid1.TableStyles.Add(myGridTableStyle); //Set the width of the Boolean Column &quot;DisContinued&quot; to 1. myGridTableStyle.GridColumnStyles[&quot;Discontinued&quot;].Width =1; </li> On the Debug menu, click Start.

You receive the exception mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">