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 ?
Thank you very much Steve. Got the grid to run perfectly on an iPad Pro with Xamarin. Really fast.
There are 2 methods on the datasource parameter:
1. This returns the object for the row. (So if you were bound to an array of Person Objects, this would return a Person)
dataSource.ResolveDataObjectForRow (path);
2. This returns the actual value for the cell. (If you were bound to an array of Person Object, and this column was bound to the FirstName property, this would return a name)
dataSource.ResolveDataValueForCell(path);
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 ?
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.