2

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 _).

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...

Any thoughts?

Locke
  • 1,133
  • 11
  • 32
  • You could overide AutoGenerate. – paparazzo Jan 23 '12 at 22:07
  • You should provide some additional info about your 'dynamic table data'. What data structure do you use actually? As yes, as BalamBalam mentioned you can override 'OnAutoGeneratingColumn'. – doblak Jan 24 '12 at 10:44
  • The data is coming back as a raw **DataTable**. While your methods both work, it still doesn't solve the issue at hand -- the issue with a column name containing a '.' – Locke Jan 24 '12 at 21:44

1 Answers1

3

For alternative replace . dot with \u2024

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.

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.

Solution will only be provided by them by changing their coding.

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

More on this here

Community
  • 1
  • 1
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
  • thanks for a solution, but I think youll have a problem when you want to update value in cell when you press enter after cell editing ... at System.Windows.Data.BindingGroup.UpdateValues() at System.Windows.Data.BindingGroup.UpdateAndValidate(ValidationStep validationStep) have you deal with this? – st35ly Nov 11 '14 at 22:01