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:
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
- 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.
- In the Data Adapter Configuration Wizard panel, click Next three times.
In the Generate the SQL statements panel, enter the following code, and then click Next:
select Productid,Discontinued from Products
- Click Finish to close the Data Adapter Configuration Wizard panel.
- Right-click SqlDataAdapter1, and then click Generate Dataset.
By default, DataSet11 is created. - Drag a DataGrid control from the toolbox to Form1.
- Right-click DataGrid1, and then click Properties.
- In the Properties window, set the DataSource to DataSet11, and then set the DataMember property to Products.
Add the following code to the Form1 Load event:
Visual Basic .NET CodeDim 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;
- 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:
DataGrid.TableStyles Property
http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagrid.tablestyles(vs.71).aspx
Keywords: kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbdatabinding kbstyle kbproperties kbwindowsforms kbctrl kbcontrol kbbug KB819345