Microsoft KB Archive/819345

From BetaArchive Wiki
Knowledge Base


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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. 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.
  2. On the View menu, click Server Explorer.
  3. Right-click Data Connections, and then click Add Connection.
  4. 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.
  5. On the toolbox, click the Data tab.
  6. Drag SqlDataAdapter to Form1.
  7. In the Data Adapter Configuration Wizard panel, click Next three times.
  8. In the Generate the SQL statements panel, enter the following code, and then click Next:

    select Productid,Discontinued from Products
  9. Click Finish to close the Data Adapter Configuration Wizard panel.
  10. Right-click SqlDataAdapter1, and then click Generate Dataset.

    By default, DataSet11 is created.
  11. Drag a DataGrid control from the toolbox to Form1.
  12. Right-click DataGrid1, and then click Properties.
  13. In the Properties window, set the DataSource to DataSet11, and then set the DataMember property to Products.
  14. 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 "DisContinued" to 1.
    myGridTableStyle.GridColumnStyles("Discontinued").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 "DisContinued" to 1.
    myGridTableStyle.GridColumnStyles["Discontinued"].Width =1;
  15. On the Debug menu, click Start.

    You receive the exception mentioned in the "Symptoms" section of this article.


REFERENCES

For more information, visit the following MSDN Web site:



Keywords: kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbdatabinding kbstyle kbproperties kbwindowsforms kbctrl kbcontrol kbbug KB819345