wpf数据网格与wcf [英] wpf datagrid with wcf

查看:78
本文介绍了wpf数据网格与wcf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在wcf中使用wpf我正在使用wcf服务绑定datagrid。我正在获取扩展数据列。我绑定只有4列额外的列也显示

i不想要额外的列



这里的代码

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

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);
           }
       }


XAML中的



in XAML

<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">

推荐答案

您必须手动创建列而不是AutoGenerating它们。然后,您可以将手动创建的列绑定到要显示的特定属性。这样的事情: -



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:-

<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>


以防万一其他人得到stu ck将来,请看看这个链接:



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



简单教程,展示如何使用WCF服务作为WPF数据网格的数据源,



问候,



尼克
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


这篇关于wpf数据网格与wcf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆