Is it possible to style row based on some condition (e.g : Red text when sales below 5$)
Hello Sutthipong,
In order to style a row in the DataGridView in our Android control suite, I would recommend using a TemplateColumn and hooking the CellUpdating event of that column. This will allow you to assign your own template to each cell of a particular TemplateColumn.
In this CellUpdating event handler, the event arguments (of the type TemplateCellUpdatingEventArgs) will have two properties, P0 and P1. P0 will return a TemplateCellInfo object which will allow you to get information about the particular row's index and the particular value that the underlying cell will have. P1 will be an EnhancedViewGroup object, which will serve essentially as the parent container for the "template" of your creation. Using these pieces of information, you can assign a template with a TextView that shows the TemplateCellInfo.Value as its text, and you can color it Red if a condition is not necessarily met.
I have attached a sample Xamarin.Android native project to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
I tried code that you suggested it works as I intended but with some problem.
The text of cell that scroll out of view still present in cell that currently show it made text unreadable.
I have reproduced this issue as well. This appears to have to do with the virtualization of the grid, because when the user scrolls some cells into view, these cells will be recycled, and so they will already have a TextView in them. So, what this is doing, is essentially adding a new TextView in addition to the one that is already there, with different text.
I would recommend in this case, that just before the TextView is created, you check the EnhancedViewGroup for a TextView that already exists, and if it does, you can get that TextView and modify it accordingly. In the case of this example, you could check the ChildCount property of the EnhancedViewGroup for anything greater than 0, as in this example, the only child should be the TextView. If a child exists, you can call viewGroup.GetChildAt(0) to get the TextView and update it.
Alternatively, another thing you could do is simply make a call to viewGroup.RemoveAllViews() before creation of the TextView in the CellUpdating event. This will clear the cells and rebuild a TextView for them as you scroll.
Thank you.Now work as intended.
Thank you for your response. I am glad that my recommendations worked for you to resolve this issue.