Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<DataGrid Name="DG" >
    <DataGrid.Columns>     
         <DataGridTextColumn Header="Header" Binding="{Binding Path=name}" />
         <DataGridTextColumn Header="Header" Binding="{Binding Path=date}" />
     </DataGrid.Columns>
</DataGrid>

C#
//dt= select * from birthdate
DG.ItemsSource = dt.DefaultView;


but in data grid it shows 2 time
Name | date                | Name | date
ABC1 | 2007-10-10 10:10:10 | ABC1 | 2007-10-10 10:10:10
ABC2 | 2007-10-10 10:10:10 | ABC2 | 2007-10-10 10:10:10
ABC3 | 2007-10-10 10:10:10 | ABC3 | 2007-10-10 10:10:10
ABC4 | 2007-10-10 10:10:10 | ABC4 | 2007-10-10 10:10:10
ABC5 | 2007-10-10 10:10:10 | ABC5 | 2007-10-10 10:10:10

how to load it for only one time without any change in xaml file


Thanks in advance
Posted
Updated 8-Jan-12 19:30pm
v2

1 solution

You need to set AutoGenerateColumns to false if you want to define your own columns, otherwise it thinks you want to add extra columns, like this
XML
<DataGrid Name="DG" AutoGenerateColumns="False" >
    <DataGrid.Columns>
         <DataGridTextColumn Header="Header" Binding="{Binding Path=name}" />
         <DataGridTextColumn Header="Header" Binding="{Binding Path=date}" />
     </DataGrid.Columns>
</DataGrid>


Hope this helps
 
Share this answer
 
Comments
01.mandar 9-Jan-12 2:11am    
Thanks It worked :)
Wayne Gaylard 9-Jan-12 3:17am    
Pleasure.
RaisKazi 9-Jan-12 2:51am    
My 5.
Wayne Gaylard 9-Jan-12 3:17am    
Many Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900