开发者

How do I suppress automatic generated columns in a DataGridView?

开发者 https://www.devze.com 2023-02-06 10:26 出处:网络
When I assign a source (a DataTable) to a DataGridView, it automatically generates columns for each data column in the data table. But I only want the columns开发者_开发技巧 I defined manually.

When I assign a source (a DataTable) to a DataGridView, it automatically generates columns for each data column in the data table. But I only want the columns开发者_开发技巧 I defined manually. How do I suppress the creation of the these columns?


You need to open the Column editor and uncheck the box Auto Generate Fields. Its towards the bottom left of the dialog.

How do I suppress automatic generated columns in a DataGridView?

If you are creating the gridview from code then there is a property:

DataGridView.AutoGenerateColumns = false;


DataGridView1.AutoGenerateColumns = false;


In VS2008 there isn't a CheckBox for disabling auto-generate columns, though the generated code in InitializeComponent() has AutoGenerateColumns=false, but it still generates the unwanted columns!

How i fixed this was by editing the .resx file (View Code from the IDE) and removing the UserAddedColumn entries entirely. ie delete these entries:

<metadata name="Column1.UserAddedColumn" type=...>
  <value>True</value>
</metadata>


<DataGrid Grid.Row="0" Name="myGrid" ItemsSource="{Binding Path=...}" AutoGenerateColumns="False">
<DataGrid.Columns>
     <DataGridTextColumn Header="Something" Binding="{...}" />
    .
    .
    .
</DataGrid.Columns>
</DataGrid
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号