Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

c# - WPF Datagrid binding errors with dots in column headers

I have a .Net datatable that I am using as a source to a WPF datagrid. The problem I have is that some of the column headers in the datatable contain dots. When binding the datatable to the datagrid, the columns containing dots are displayed, but contain no data.

After reading around on the net I have worked out that the dots are a special notation used within the databinding engine and are confusing the datagrid's binding to the table.

I have tried manually creating the datagrid columns + bindings and adding square brackets to negate the dots. This works fine but then breaks when I sort a column. This article mentions hooking into the sorting event to remove the [] on the sorting event. There wasnt much detail of how to achieve this and what I did try did not seem to get rid of the error.

Please let me know if you require anymore information.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As you've discovered, dot notation for anything other than Binding is problematic with WPF. What I'd recommend is to revise your headers to alias the column names with dot notation:

Col.A should be Col_A
Col.B should be Col_B
etc...

If the headers are coming from a direct SQL query, alias the sql column names in the same manner.

Going down the path of using the dot notation will just continue leading into one hackish fix to resolve the previous 'fix'. All of this can be easily resolved by just revising your naming conventions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...