Hello,
I am currently trying to set a single cell specific style in code behind. I have read/seen a bunch of examples of how to handle this with triggers. I specifically want to get this accomplished however in code behind. I attached a sample to demo on what I am trying to achieve. The XML document that I am using has 3 columns of information. The first column is the label. The 2nd and beyond columns are the data. I want to mark in red the cells that are different from column 2. The amount of data columns could be 2 or more. This example shows only 2. Please visit MarkDifferences() in the sample for clarity on what I want.
I am really curious/need guidance as to why
1. CellValuePresenter.FromCell() returns null for me?
2. Why Cell.Field.Settings.CellValuePresenterStyle seems to set the style for the entire column instead of just the cell.
If more info is needed I will provide.
Chad
Thanks a ton , this solution made my day
I did get the service release and I see the new event. I tested it and it works for me. Thanks for your responses.
1. Yes typo in style is wrong, I corrected it
2. I figure "Field" was the entire column glad it was confirmed.
Hello Chad,
A better event to use would be the CellsInViewChanged event which was introduced in a service release for NetAdvantage for .NET 2009 Vol. 2. The issue with the CellValuePresenter always being null is that the event that you are using is too early in the order events and the CellValuePresenters have yet to be created and added to the visual tree.
I have tested this with the latest service release, build 9.2.20092.2160, and the CellsInViewChanged event fires after the cells have already been brought in to view, resulting in the CellValuePresenters existing and your logic working.
Please note that there's also a slight typo in your logic. You have "DifferencePropertyDataStyle" instead of "DifferentPropertyDataStyle".
As to why setting c.Field.Settings.CellValuePresenterStyle sets the color for the whole column, this is because you are telling the code to get the Field that the cell is contained in and the Settings property for that field apply to all cells in that field. The approach you are taking, where you set the style on individual cells, is the correct approach.
I was wondering if anyone has any input on this?