Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

sql

linq

wpf

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)

like image 683
Serak Shiferaw Avatar asked Nov 03 '22 10:11

Serak Shiferaw


1 Answers

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">
like image 57
Tomas00 Avatar answered Nov 08 '22 03:11

Tomas00