势必数据视图DataGrid标题排序错误 [英] Datagrid header sort error bound to dataview

查看:169
本文介绍了势必数据视图DataGrid标题排序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,相信简单的东西,只是不能得到它的抓地力。我对窗口的我的数据上下文视图模型。它我有一个私人的数据表,也就是从数据库查询填充。没问题。我有一个公共的数据视图属性{获得;设置;}返回的DataTable.DefaultView。我窗体上的DataGrid绑定到视图模型的数据视图属性的路径和运行方式。没问题,过来,列中显示正常,点击行,没问题。

现在,问题。点击什么我还以为头自动处理数据排序,并将其与一个错误出现了

 'MyTable的'类型不具有名为[MyColumn]的财产,所以不能进行排序的数据收集。

在这里混淆的部分。绑定是从MyTable.DefaultView的VIEW(MyTableView)发起,它也有一个专栏MyColumn,因为它是在网格中正确显示。我在想什么。

只是为了澄清,这里的一些从视图模型

在XAML和code的

 <数据网格的AutoGenerateColumns =FALSE
   NAME =dataMyData
   的ItemsSource ={绑定路径= MyTableView,NotifyOnSourceUpdated = TRUE,NotifyOnTargetUpdated = TRUE}
   的SelectedItem ={绑定路径= MyCurrentViewRecord,模式=双向}>  < D​​ataGrid.Columns>
    < D​​ataGridTextColumn标题=#
        绑定={结合路径= [MyRecord]
        NotifyOnSourceUpdated = TRUE}/>    < D​​ataGridTextColumn标题=MyColumn
        绑定={结合路径= [MyColumn]
        NotifyOnSourceUpdated = TRUE}/>  < /DataGrid.Columns>
< / DataGrid的>私人数据表MyTable的;公开数据视图MyTableView
{{返回MyTable.DefaultView; }}


解决方案

其实,找到了......

我不得不明确添加

  SortMemberPath =MyColumn(为DataGrid的列定义)

据窒息在绑定[]括号,但如果我不包括在绑定的支架,因为它是用于显示的列源,它不会显示数据...

I'm having a problem and believe something simple, just can't get a grip on it. I have a View model for my data context of the window. On it I have a private "DataTable" that is populated from a database query. No problem. I have a public DataView property {get;set;} that returns the DataTable.DefaultView. I bind the DataGrid on the form to the path of the DataView property on the view model and run the form. No problem, comes up, columns displayed properly, click on the rows, no problem.

Now, the problem. Click on the header for what I thought auto-handles the data sorting and it comes up with an error that

'MyTable' type does not have property named '[MyColumn]', so cannot sort data collection.

The confusing part here. The binding is to the VIEW (MyTableView) originating from MyTable.DefaultView, and it DOES have a column "MyColumn" as it is properly displayed in the grid. What am I missing.

Just to clarify, here's some of the xaml and code from the view model

<DataGrid AutoGenerateColumns="False" 
   Name="dataMyData" 
   ItemsSource="{Binding Path=MyTableView, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}"
   SelectedItem="{Binding Path=MyCurrentViewRecord, Mode=TwoWay}" >

  <DataGrid.Columns>
    <DataGridTextColumn Header="#" 
        Binding="{Binding Path=[MyRecord], 
        NotifyOnSourceUpdated=True}" />

    <DataGridTextColumn Header="MyColumn" 
        Binding="{Binding Path=[MyColumn], 
        NotifyOnSourceUpdated=True}"/>

  </DataGrid.Columns>
</DataGrid>



PRIVATE DataTable MyTable;

public DataView MyTableView
{ get { return MyTable.DefaultView; }}

解决方案

Actually, found it...

I had to explicitly add

SortMemberPath="MyColumn"   (for the column definition of the DataGrid)

It was choking on the [] brackets in the binding, but if I didn't include the brackets in the binding as it is a column source for display, it wouldn't show the data...

这篇关于势必数据视图DataGrid标题排序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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