Serak Shiferaw
Serak Shiferaw

Reputation: 1021

how can i correct wpf datagrid column name redundancy in visual studio 2012

private void ViewWinLoaded(object sender, RoutedEventArgs e)
    {
        var stud = from s in data.Students
                             select s;
         Student[] st=stud.ToArray<Student>();
         datagrid.ItemsSource = st;

    }

the above one is my C# code.

<DataGrid x:Name="datagrid" HorizontalAlignment="Left" Height="232" VerticalAlignment="Top" Width="461">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Path=StudentID}" ClipboardContentBinding="{x:Null}" Header="StudentID"/>
            <DataGridTextColumn Binding="{Binding Path=FirstName}" ClipboardContentBinding="{x:Null}" Header="First Name"/>
            <DataGridTextColumn Binding="{Binding Path=LastName}" ClipboardContentBinding="{x:Null}" Header="Last Name"/>
            <DataGridTextColumn Binding="{Binding Path=Gender}" ClipboardContentBinding="{x:Null}" Header="Gender"/>
            <DataGridTextColumn Binding="{Binding Path=GPA}" ClipboardContentBinding="{x:Null}" Header="GPA"/>
        </DataGrid.Columns>
  </DataGrid>

what I am trying to achive is to use my own column name, not the column name in the dB. But when i run the code, it displays my custom column and the column name from the db at the same time(cascaded name)

Upvotes: 5

Views: 977

Answers (2)

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

Another way to achieve this result, you can set to every public property of your Student class attribute DisplayName.

Upvotes: 0

Tomas00
Tomas00

Reputation: 117

Prevent the DataGrid from generating columns by setting AutoGenerateColumns property to false.

<DataGrid x:Name="datagrid" AutoGenerateColumns="False"
HorizontalAlignment="Left" Height="232" VerticalAlignment="Top" Width="461">

Upvotes: 2

Related Questions