无法在将 DataView 实例作为项目源的 WPF 数据网格中显示数据

发布于 2024-09-02 12:37:10 字数 666 浏览 8 评论 0原文

我正在使用 WPF 工具包中的 DataGrid 对象。我将 DataGrid 对象绑定到 DataTable 实例的默认视图,如以下代码中声明的:

WeatherGrid.ItemsSource = weatherDataTable.DefaultView;

weatherDataTable 有三列。第一列定义为包含字符串数据类型。其他两列定义为包含双精度数据类型。当应用程序退出调用声明中所表达的绑定的函数时,DataGrid 对象显示第一列的数据,但不显示其他列的数据。当我在调试器的立即窗口中键入以下内容时:

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

我得到一个数字,但这与显示的内容不符。为什么只有第一列可见,如何才能使所有数据可见?我将在下面保留 DataGrid 对象的 XAML 定义:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬花如无物 2024-09-09 12:37:10

事实证明,对于我的第二和第三列,我一直使用不正当的列名称。我最终希望我的 DataTable 是动态的,因为它可以具有可变数量的列,并且我希望按日期唯一标识每一列。因此,我附加了两个字符串,一个带有名称,另一个带有由“/”分隔的数字。这似乎导致了 DataGrid 对象的一些绑定问题。

为了解决这个问题,我把唯一标识日期的字符串改成了一年中的某一天的数字。结果,我能够显示数据。

有趣的是,在 ASP.NET 中绑定到 GridView 时,在 DataTable 列名称中使用斜杠时,不会出现此类问题。

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.

離人涙 2024-09-09 12:37:10

事实上,列绑定名称区分大小写,并且必须与基础数据视图列名称完全匹配。

In fact the column Binding name is case sensitive and must match the underlying dataview column names exactly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文