I have a grid bound to a data source and I wish to use a converter to change some of the values in the grid. I've used a converter before to change some of the other properties such as font color and they worked fine, but when it comes to changing content there's an issue.
I've debugged the code and the converter is getting correctly called and is return the correct values, but the raw values are still displayed in the grid. My converter is just returning strings, is there a reason why it's unable to render them?
Thanks
<DataPresenter:Field Name="myField" Width="Auto"> <DataPresenter:Field.Settings> <DataPresenter:FieldSettings> <DataPresenter:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type DataPresenter:CellValuePresenter}" > <Setter Property="" Value="{Binding RelativeSource={RelativeSource Self}, Path=Content, Converter={StaticResource myConverter}}" /> </Style> </DataPresenter:FieldSettings.CellValuePresenterStyle> </DataPresenter:FieldSettings> </DataPresenter:Field.Settings> </DataPresenter:Field>
One thing tough, is it possible to just define what is displayed in the grid, rather than changing the underlying value?
so "a" would get displayed as "b" for instance, but it'd still be stored as "a"
thanks
You have to cast the Record to DataRecord, because the DataRecord exposes the Cells collection :
(e.Record as DataRecord).Cells[...].Value. The cells collection has a int and string indexers, so you can access the specific field.
Once the record initialised method gets called, and i access the record using e_.Record, how can I access the cell I want?
(I have it's field name)
No, you cannot do that. However, you can use the InitializeRecord event and make the appropriate changes there. In this event you can use e.ReInitialize if you need to perform this only on initial load.