Binding Items, got repeated columns again

Apr 1, 2009 at 5:16 PM

Here is my problem

i have a Datagrid which has its own columns in XAML formate like

<dg:DataGrid x:Name="dataGVReport" >

<dg:DataGridTextColumn Header="Product_name" Width="SizeToCells" Binding="{Binding Path=Product_name}"/>
<dg:DataGridTextColumn Header="Price" Width="SizeToCells" Binding="{Binding Path=Price}"/>
<dg:DataGridTextColumn Header="Qua" Width="SizeToCells" Binding="{Binding Path=Qua}" />


cuz the itemsource is variable, so i cant just bind it initially, like ItemsSource="{StaticResource myData}"

BUT i did bind in the C# code like 

DataView dv = new DataView(tmpTable);
dataGVReport.ItemsSource = dv;

Alrit, now the problem is coming, after this binding, the datagrid got "twice" columns, which are original columns and the repeated columns from DataTable. Therefore i have repeated columns in my datagrid, how can i get this issue sorted?

i have columns like :

Product_name  Price Qua primary_id  Product_name  Price Qua

Please help and really appreaciated 

Apr 1, 2009 at 6:44 PM
I think you just need to set the AutoGenerateColumns property on DataGrid to false.  This property is true by default, and if you add your own columns to the Columns collection while AutoGenerateColumns is true, the default behavior is to display those columns and then append the autogenerated columns to the end of the collection.  If you set AutoGenerateColumns to false, this should prevent the second set of columns from being generated and appended to the end of your collection.