Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Column Header Name in XAML- WPF

I would like to set the user defined column Header in a WPF datagrid that is bound to a database.

for displaying ServerID, EventlogID I would like to display as Server, Event Log in the column header.

I have tried these already ...

 <DataGrid x:Name="dataGrid1" ItemsSource="{Binding}" AutoGenerateColumns="True" >
     <DataGrid.Columns>
        <DataGridTextColumn Header="Server" Width="Auto" IsReadOnly="True"  Binding="{Binding Path=ServerID}" />
            <DataGridTextColumn Header="Event Log" Width="Auto" IsReadOnly="True"  Binding="{Binding Path=EventLogID}" />
      </DataGrid.Columns>
   </DataGrid>

This works fine, and it changes the Column Header and the datas are also displayed.

But my problem it is displayed twice as first two column header from XAML and other two column header from the DB.

  |Server|Event Log|ServerID|EventLogID|

how to overcome this replication ? Kindly help !

like image 675
Indhi Avatar asked Dec 19 '12 12:12

Indhi


1 Answers

That's because you left the AutoGenerateColumns="True" remove it, and there will be no more duplication.

You're currently adding the columns once, automatically, and then a second time, manually!

like image 157
Louis Kottmann Avatar answered Oct 16 '22 09:10

Louis Kottmann