DataTable 列名称包含方括号 [name]
我在向 DataGrid 添加名为“[name] version”的列时遇到问题。如果我有类似“[name]”或“version [name]”的内容,则转义、unicode 或将所有工作加倍。仅当右括号后面有字符时才会出现问题。 “[[name] version]”也可以,但不是我需要的。
我使用 WPF 和 C#,这行代码将 DataTable 绑定到 DataGrid。
datagrid1.ItemsSource = dataTable1.DefaultView;
我收到的错误是:
“PropertyPath '语法”中存在语法错误 “Binding.Path '[name]' 中出现错误... '版本'",'"。
I am having a problem with adding a column named "[name] version" to a DataGrid. If I have something like "[name]" or "version [name]" then escaping, unicode or doubling all work. There only appears to be a problem when there are characters after the closing bracket. "[[name] version]" works too but is not what I need.
I am using WPF and C#, this line of code binds the DataTable to the DataGrid.
datagrid1.ItemsSource = dataTable1.DefaultView;
The error I receive is:
Syntax error in "PropertyPath 'Syntax
error in "Binding.Path '[name]' ...
'version'",'".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SQL Server 允许在列名周围使用方括号或双引号...您可以使用双引号吗?
SQL Server allows square brackets or double quotes around column names... can you use double quotes instead?
我刚刚编写了一个辅助函数,它更改 ColumnName 属性以删除 [] 和空格等特殊字符,并且我只需将这些字符保留在 Caption 属性中。然后我将 Caption 绑定到列标题,将 ColumnName 绑定到 DisplayMemberBinding。
I've just written a helper function which changes the ColumnName property to remove special characters like [] and spaces and I simply leave these characters in the Caption property. So then I bind the Caption to the column header and the ColumnName to the DisplayMemberBinding.
您需要做的就是避开右方括号。
看:
All you need to do is escape the closing square bracket.
See: