绑定到C#/WPF中DataTable中包含句点的字段 [英] Binding to fields containing a period in DataTable in C#/WPF

查看:144
本文介绍了绑定到C#/WPF中DataTable中包含句点的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL CE数据库,该数据库不受我的控制,它具有.格式的字段,并在列名中带有句点.列将始终是不同的,因此我不能具有强类型的数据字段.我的任务是将动态表数据显示到DataGrid中.

I have a SQL CE database, which is beyond my control, that has fields in the format of ., complete with a period in the column name. The columns will always be different, so I cannot have a strong-typed data field. I've been tasked with displaying dynamic table data into a DataGrid.

通常,这很容易-自动生成列,一切都很酷.简单的例子.

Normally, this would be easy -- auto-generate the columns and everything is cool. Easy example.

但是,由于'.',我不允许这样做.列名称中的字符会破坏绑定.

However, I'm not allowed to do this, since the '.' character in the column names nukes the binding.

现在,我正在尝试向数据集添加一层翻译(可能必须维护将.转换为_的字典).

Right now, I'm trying to add a layer of translation to the dataset (probably will have to maintain a dictionary with translations of . to _).

我的问题是-有更好的方法吗?我回想起有一段时间关于能够在DataTable中使用SourceColumnName的事情,但是我没有看到它.有一个标题",但我无法绑定到该标题...

My question is -- is there a better way? I recall something a while back about being able to have a SourceColumnName in a DataTable, but I didn't see it. There's a "Caption," but I cannot bind to that...

有什么想法吗?

推荐答案

. dot替换为\u2024

For alternative replace . dot with \u2024

如果您向Microsoft人员提出此问题,他们将告诉您(您的问题)是因为WPF DataGrid在存在数据源时支持子属性数据映射".因此,. dot尝试解析为数据表中包含的子对象.

If you put this question to Microsoft people, they will tell you that this (your problem) is because WPF DataGrid supports "sub properties data mapping" when there is a data source. For this reason, . dot tries to resolve to sub object contained in your DataTable.

在下一行中,他们会礼貌地要求您将列名中的. dot替换为_ Underscore.

In the next line they will politely ask you to replace your . dot to _ Underscore in column name.

(http://social.msdn.microsoft.com/Forums/en/wpf/thread/7d84c8f2-2709-4642-a259-739036ffd2a6)

但这既不是解决方案,也不是替代方案.

But that's neither a solution nor an alternative.

只能通过更改他们的编码来提供解决方案.

替代.与\u2024在一起,这是 C/C ++/Java的unicode字符

For alternative replace . with \u2024 This is the unicode character for C/C++/Java

更多在这里

这篇关于绑定到C#/WPF中DataTable中包含句点的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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