无法显示在具有数据视图实例作为项目源的WPF数据网格数据 [英] Unable to display data in a WPF datagrid that has a DataView instance as the items source

查看:130
本文介绍了无法显示在具有数据视图实例作为项目源的WPF数据网格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用从WPF工具包DataGrid对象。我DataGrid对象绑定到如以下code声明的DataTable实例的默认视图:

  WeatherGrid.ItemsSource = weatherDataTable.DefaultView;

weatherDataTable有三列。第一列被定义为包含字符串数据类型。其他两列被定义为包含双数据类型。当应用程序退出调用在声明中,对于第一列的DataGrid对象显示的数据,而不是其他列pssed结合作为前$ P $的功能。当我在调试器立即窗口中键入以下内容:

 ((DataRowView的)WeatherGrid.Items [0])。行[1]

我得到一个数字,但这并不与正在显示的内容相对应。为什么只有第一列可见的,我怎么能得到所有的数据可见?我会离开我的XAML定义如下DataGrid对象:

 <工具箱:DataGrid的保证金=12.726,77.71,12,0NAME =WeatherGridHEIGHT =500Grid.Row =1VerticalAlignment =顶部 CanUserAddRows =FALSECanUserDeleteRows =FALSEIsReadOnly =真/>


解决方案

事实证明,我的第二和第三列,我一直在用不正当的列名。我最终想我的数据表是动态的,因为它可以有一个可变的列数,我想按日期唯一标识每一列。所以,我追加两个字符串,其中一个名字和一个由/分隔的数字。看来,这引起了一些有约束力的问题,一个DataGrid对象。

为了解决这个问题,我改变唯一地识别与编号为一天中的一年一年的日期串。其结果是,我能够显示数据。

有趣的是,注意DataTable中列名中使用斜线时ASP.NET绑定到GridView的时候都没有这样的问题。

I am using a DataGrid object from the WPF toolkit. I am binding the DataGrid object to the default view of a DataTable instance as declared in the following code:

WeatherGrid.ItemsSource = weatherDataTable.DefaultView;

weatherDataTable has three columns. The first column is defined to contain a string data type. The other two columns are defined to contain double data types. When the application exits the function that calls the binding as expressed in the declaration, The DataGrid object displays data for the first column, but not the other columns. When I type the following in the immediate window in the debugger:

((DataRowView)WeatherGrid.Items[0]).Row[1]

I get a number, but this doesn't correspond with what is being displayed. Why is only the first column visible, and how can I get all of the data to be visible? I'll leave my XAML definition for the DataGrid object below:

<toolkit:DataGrid Margin="12.726,77.71,12,0" Name="WeatherGrid" Height="500" Grid.Row="1" VerticalAlignment="Top" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" />

解决方案

It turns out that for my second and third columns, I have been using perverse column names. I ultimately wanted my DataTable to be dynamic in that it could have a variable number of columns, and I wanted to uniquely identify each column by date. So, I appended two strings, one with a name and one with numbers delimited by "/". It seems that this caused some binding problems with a DataGrid object.

In order to solve this problem, I changed the string uniquely identifying the date with a number for the day in the year and the year. As a result, I was able to display the data.

It is interesting to note that there are no such problems when using slashes in DataTable column names when binding to GridViews in ASP.NET.

这篇关于无法显示在具有数据视图实例作为项目源的WPF数据网格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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