I just need to change the color of a column of cells conditionally on the contents of the cell that is being supplied by a standard data source helper. This is what I intend to do:
public override IGGridViewCell CreateCell(IGGridView gridView, IGCellPath path) { IGGridViewCell cell = base.CreateCell(gridView, path);
if (cell.Text == "...")
{ cell.TextColor = UIColor.Red }
}
But Xamarin runtime tells me that I cannot call the base.CreateCell here. Obviously I am doing something wrong. Any suggestions ?
Hi,
Technically you're not doing anything wrong. But Xamarin is really buggy in this area. Since CreateCell is a IGGridViewDataSource delegate method, they won't let you call the base implementation. Even though you're deriving from a class, that has to have an implementation of it. Honestly, i have no idea why they haven't fixed this yet.
Anyways, you can just implement the method yourself, as its straight forward:
public override IGGridViewCell CreateCell (IGGridView gridView, IGCellPath path) { IGCellPath normPath = this.NormalizePath (path); IGGridViewColumnDefinition colDef = this.Columns [normPath.ColumnIndex]; if(colDef != null) { IGGridViewCell cell = colDef.CreateCell (gridView, path, this); return cell; } return null; }
Another option, is to create your own IGGridViewColumnDefinition, and override it's CreateCell method. Then you'll be dealing with that column directly.
Hope this helps,
-SteveZ
I went the second route as shown below:
public class iconFileFlagsColumnDefinition : IGGridViewColumnDefinition { public iconFileFlagsColumnDefinition(string key) : base(key) { } public override IGGridViewCell CreateCell(IGGridView gridView, IGCellPath path, IGGridViewDataSourceHelper dataSource) { IGGridViewCell cell = base.CreateCell(gridView, path, dataSource); cell.TextLabel.TextColor = UIColor.Red; return cell; } }
This unconditionally changes all rows to red. How do I access the value currently in the cell so that I can conditionally paint ?