Hi,
I am trying to highlight some cells in my XAMDatagrid. When there are more columns/rows than that can be displayed in the visible area and I scroll to see the data, I find that the cell highlight randomly doesn't happen. If I scroll left/right or up/down again then the cells gets highlighted. But there are chances that some other cells now do not have the backcolor.
How can I fix this?
Thanks.
Poornima
Hi Poornima,
I was wondering if you had any further questions or if there was anything more I could help you with.
Because of virtualization, you would not directly apply a style to rows or cells that are not currently visible. The idea is to apply a style based on some value or combination of values in the current or other rows or cells. Or possible you might need to set a control property value in your viewmodel that would cause a style to be applied when the appropriate row or cell came into view.
My sample is arbitrarily adding a background color to all of the cells in the first visible row and clearing all of the other rows so that only one row shows the background color changed.
Your best approach is to use styles, converters and triggers bound to data values. A converter can be passed a cell or a row and return a value based on a combination of values. A trigger can also be bound to values in the datacontext.
So you indirectly use values in other rows and cells to determine if the style should be applied as the row and cell come into view.
Please let me know if you have any questions.
Any updates? I atleast want to know if this is possible to achieve or not!!!
Thanks,
Hi Marianne,
I am not sure if I haven't explained it right to you.
Lets say I have some 100 records in my grid, and I the grid displays 10 at a time in the visible area.
1. After I assign some data to my grid, I want to set the backcolor of few cells in Record1,2,3 of the grid with some color.
2. When I scroll to see the records from 10 - 20, still the grid should retain the color only for Record 1,2,3 and not the 10,11,12 th records of the grid. (Your latest sample doesnt work this way)
3. Next as a result of some event in my application, lets say I want to color the some cells in the 100th record, then irrespective of what my grid shows, I should be able to set the color.
Is it possible to achieve this?
Again in the FieldLayoutIntialized event, only the fields are initialized. How can I access the cellvaluepresenter in any record in this event? My record count is 0 at this stage.
Regards,
I’m returning your sample with events wired and debug statements so that you can see the order and frequency of events and that when the FieldLayoutInitialized event is fired the fields are there. See the output for a display of the fields.
As for the behavior you are seeing using your code to apply background color to cells, you are adding color to the first row that is being displayed, which is at the top of the viewable area. See this link for an explanation of cells, cellValuePresenters and cell virtualization.
http://help.infragistics.com/Help/NetAdvantage/WPF/2012.1/CLR4.0/html/xamData_Cells_CellValuePresenters_and_Cell_Virtualization.html
I modified your sample to clear all the visible rows except the first. Run my updated sample and you should see the behavior that you expected.