Hi,
I'm looking for an example to the implementation of viewForSectionColumn but in C#. The examples and documentation are all in objective C.
I'm using a datasource helper.
Thanks
Kathy
Hi Kathy,
Sure!
Basically, you just need to override this method on your implementation of your IGGridViewDelegate:
public class GriDelegate : IGGridViewDelegate { public override UIView ResolveSectionColumnView (IGGridView gridView, int section) { UIView v = new UIView (new RectangleF (0, 0, 0, 100)); v.BackgroundColor = (section%2==0)? UIColor.Red : UIColor.Green; return v; } }
You'll then just return the view you want to display, based on the section. One thing that you have to specify, is the height of the view. In the above example, the height i'm specifying is 100pts.
And here is the code to setup the grid:
grid.Delegate = new GriDelegate (); IGGridViewDataSourceHelper dsh = new IGGridViewDataSourceHelper (); dsh.GroupingKey = "firstName"; dsh.Data = IGSalesmanItem.GenerateData (100).ToArray (); grid.DataSource = dsh;
Hope this helps!
-SteveZ
Hi Steve,
That did help and thanks for answering so quickly. One other question, how do I get the data that's in column 0 connected to the columnView? right now what shows is the background color.
First, let me show you how you would resolve the section values for that grouping:
public override UIView ResolveSectionColumnView (IGGridView gridView, int section) { IGGridViewDataSourceHelper dsh = (IGGridViewDataSourceHelper)gridView.DataSource; NSString key = (NSString)dsh.Sections [section]; UITextView v = new UITextView (new RectangleF (0, 0, 0, 100)); v.Text = key; v.BackgroundColor = (section%2==0)? UIColor.Red : UIColor.Green; return v; }
This would show you the value that the particular section is grouped on.
Now, if you wanted to display one of the values in the row, you could look up the value via the path:
NSObject obj = dsh.ResolveDataValueForCell(new IGCellPath(0,section,0));
The code above will give you the value for the First Row, in the First Column, of that particular section.
Again, thanks it way very helpful. What I did was use the value from column 0 in an NSObject as you described and the section column reflects that value--great!
But now column0 shows up again in the regular part of the grid. So the value is in the Section column and in the 1st column of the moving section.
I guess I see why that is happening, but I thought the column0 would be the section column. Do you have any suggestions for this?
I actually made the column width 0 and that works.
Thanks.
Hi Steve
col 0 is NOT the column I'm grouping on. I'm using the grouping to make a section header. I did use the fieldsToIgnore, but the dsh seems to not recognize that, I guess because I am adding col0. ( dsh.ColumnDefinitions.Add(col0);) If I don't add column0 it doesn't resolve.
To be clear, is Column 0 the column you're grouping on?
If so, then to have the column not auto generated, you can do the following:
grid.Delegate = new GriDelegate (); IGGridViewDataSourceHelper dsh = new IGGridViewDataSourceHelper (); dsh.GroupingKey = "firstName"; dsh.FieldsToIgnore.Add (new NSString("firstName")); // <-- do not auto generate this column. dsh.Data = IGSalesmanItem.GenerateData (100).ToArray (); grid.DataSource = dsh;