Click here to Skip to main content
15,920,110 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
I am using wpf with wcf i am binding datagrid with wcf service. i am getting extension data column. i am binding only 4 columns extra column also displaying
i dont want extram column

code here
C#
private EmployeeServiceReference.EmployeeServiceClient employeeservice = null;

       private void Window_Loaded(object sender, RoutedEventArgs e)
       {
           employeeservice = new EmployeeServiceReference.EmployeeServiceClient();
           try
           {
               gv.ItemsSource = employeeservice.ListEmployees();
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

in XAML
XML
<Grid>
       <Grid.RowDefinitions>
           <RowDefinition Height="*"></RowDefinition>
           <RowDefinition Height="*"></RowDefinition>
       </Grid.RowDefinitions>
       <Grid.ColumnDefinitions>
           <ColumnDefinition Width="*"></ColumnDefinition>
       </Grid.ColumnDefinitions>
       <DataGrid Name="gv" Grid.Row="0" Grid.Column="0" AutoGenerateColumns="True">
Posted

You will have to manually create your columns instead of AutoGenerating them. Then you can bind your manually created columns to the specific properties you want to display. Something like this:-

XML
<DataGrid AutoGenerateColumns="False">
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding Path=Name}" Header="Name"/>
                        <DataGridTextColumn Binding="{Binding Path=Surname}" Header="Surname"/>
                        <DataGridTextColumn Binding="{Binding Path=Age}" Header="Age"/>
                        <DataGridTextColumn Binding="{Binding Path=EmployeeNo}" Header="Employee Number"/>
                    </DataGrid.Columns>
                </DataGrid>
 
Share this answer
 
Just in case anyone else gets stuck with this in the future, take a look at this link:

http://www.codearsenal.net/2012/09/wcf-service-and-wpf-client-datagrid.html#.Us_cSfRdXsk[^]

Simple tutorial showing how to use a WCF service as a data source for a WPF data grid,

Regards,

Nick
 
Share this answer
 

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