Hey Everyone
Im trying to get the value out of a cell.
I want to apply Cell Level Styles based on the value in a cell. I have bound a DataTable to the DataSource property of the DataGrid
I am using the InitializedRecord event, which gives me each record as it created in the grid.
However, I have search and searched and can not find out an easy way of viewing the data in the cells?
...
On a side note, once I figure out how to examine the data in the cells, what would be the best way to apply cell level styles?
I need to do different text, and text formats and even as far as shading and background color changes.
Thanks
DK
That is because the Record class is a base class for DataRecord, GroupByRecord and ExpandableFieldRecord. So you need to do something like the following:
DataRecord dr = xamDataGrid1.ActiveRecord as DataRecord;
if ( dr != null )
{
Cell cell = dr.Cells["Salary"];
cell.Value = 1000000;
}
You can also get to the CellValuePresenter for a specific cell that is in view by calling the CellValuePresenter's FromRecordAndField static method. If that record isn't in view then the method returns null.
Hey Joe,
Thanks for the info, that makes good sense.
However, is ther an easy way in C# to just look at the value in the cell on the record ?
I dont see any .Value or .CellValue on the record or field object.
Hi DK,
The best way to do this is to provide a style for the CellValuePresenter (or even for the Editor within the cvp). You can set it for an individual Field thru the Field.Settings.CellValuePresenterStyle property (or EditorStyle property). Then you can use a binding with a path of "Value" and relative source of 'Self' (if the property is being set directly on the CellValuePresenter) or "TemplatedParent" if the property is being set on an element with the ControlTemplate of the style. You then provide a custom converter, a class you write that implements the IValueConverter interface. e.g.
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=Value, Converter={StaticResource MyValueToBackgroundConverter}}">
To see some additional examples of this approach check out the following thread http://forums.infragistics.com/forums/t/1679.aspx
I hope this helps