Hi - I've implemented my grids to include buttons in the SectionHeaderView. I've noticed that when there are no items in the grid the Section Header View does not appear. I understand why this is probably happening but I'm wondering if I can avoid rebuilding all my grids to not use the Section Header View.
I tried overriding the IGGridViewDataSourceHelper.NumberOfSections to always be 1, but this did not cause the IGGridViewDelegate.ResolveSectionHeaderView to fire and build my custom buttons.
Any thoughts would be nice if I can avoid re-doing all the implementations of buttons in my grids.
Thanks.
One quick note that caused me trouble.
Make sure that this.Data is initialized. Even as an empty NSObject array or the headers still will not be rendered.
Ah, sorry, i misread.
Thats tricky since if you have no rows, then you technically have no sections.
What you could do is check if your array has zero items and tell the dsh that there is one row and then when it asks for that cell, you would just return null.
Something like this:
public class GridDSH : IGGridViewDataSourceHelper { public override int NumberOfRowsInSection (IGGridView gridView, int section) { int count = this.Data.Length; if (count == 0) return 1; return count; } public override IGGridViewCell CreateCell (IGGridView gridView, IGCellPath path) { if (this.Data.Length == 0) return null; IGCellPath normPath = this.NormalizePath (path); IGGridViewColumnDefinition colDef = (IGGridViewColumnDefinition)this.Columns [normPath.ColumnIndex]; if(colDef != null) { IGGridViewCell cell = colDef.CreateCell (gridView, path, this); return cell; } return null; } }
-SteveZ
Hey Stephen - So in your sample its returning a results set of 200 items. If you change the line that states:
dsh.Data = IGSalesmanItem.GenerateData (200).ToArray ();
to
dsh.Data = IGSalesmanItem.GenerateData (0).ToArray ();
You will then see that the red section header view does not appear.
Any thoughts on how to still get it to appear when data items in the array are = 0?
Hi,
As long as you implement the method, it will always display a section header, even if you have only 1 section displayed.
I've attached a sample that does show it working.
Let me know if it doesn't work for you.