Sunday 15 March 2015

c# - wpf datatable column name can not have slash / -



c# - wpf datatable column name can not have slash / -

i'm new wpf. i'm having weird issue create table, here code have:

datatable table = new datatable(); table.columns.add("request/sec", typeof(string)); datarow newrow = datatable.newrow(); newrow["request/sec", "na");

but shows column name "request/sec" , empty row

however, if do:

datatable table = new datatable(); table.columns.add("test(request/sec)", typeof(string)); datarow newrow = datatable.newrow(); newrow["test(request/sec)", "na");

then it's working, shows column name correctly, , row value "na"

i have no thought why happening, know sounds ridiculously. can help?

note: tried "//", "/", "\/", @ can not hardcoded column names, it's dynamic generated logic, used above code examples

there issues creating bindings when property name contains reserved characters . , /. property path parser doesn't handle them. have couple options:

instead of having grid automatically generate columns, define them yourself, , columns reserved characters, bind info row's indexer instead of column name:

<datagridtextcolumn binding="{binding path=[request/sec]}" header="request/sec" />

if care column name because want command column header text, declare columns manually, give column "legal" name, , set header above.

c# wpf wpf-controls wpfdatagrid

No comments:

Post a Comment