Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
195
Change the text color of a cell
posted

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 ?

Parents
No Data
Reply
  • 40030
    Offline posted

    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

Children