I'm building an application using Xamarin for iOS and I'm trying to implement a simple data grid table. Following along with some of the examples I tried using the IGGridViewDataSourceHelper because it greatly simplifies handling the data for me. Initially, I built a custom test class that inherited from NSObject. I created a list of these objects and set them to the DataSourceHelper.Data and things worked perfectly. Now I need to create a list of generic Dictionary<string,object> items and pass it in. This is where the problem occurs because Dictionary does not inherit from NSObject.
I'm sure building a table based off a List of Dictionaries should be a pretty standard problem, so what is the work around for this issue?
Hi Clint,
For that, i'd recommend creating an custom object that derives from NSObject and have the Dictionary be a property on the object.
public class Dummy : NSObject{ public List<string, object> Props{get;set;}
}
I can put together a sample for you, but I have a couple of questions. Is this dictionary supposed to represent one column? Or is each key in the dictionary supposed represent a column? If the latter, then it becomes a bit trickier, or at least may have a couple of caveats. But either way, i should be able to throw something together for you.
-SteveZ
Thanks SteveZ,
Each Dictionary in the list would represent a single row in the grid. Each property in the dictionary would be a column in the row.
So far, I have been using a list of IGGridViewColumnDefinition set into the ColumnDefinitions to pick which fields out of the dictionary I want to display and have AutoGenerateColumns set to false.
Ok, perfect.
I've created a sample that does just that.
I had to create a custom column to handle the lookup, but I believe this should do what you're looking for.
That should get me on the right track for this. I ended up adding a small method to the Data class to reduce the number of times that I have to convert string to NSString in actual code.
public void Add(string key, string value){ if (_props == null) { _props = new NSMutableDictionary (); } _props.Add(new NSString(key), new NSString(value)); }