If I fix the first column in my dataset, it gets displayed again as a second column ; so its duplicated. What am I doing wrong?
// If we want the first column locked in place.. IGGridViewColumnDefinition col1 = new IGGridViewColumnDefinition ("name"); configdsh.FixedLeftColumns.Add (col1); // Add data to the grid configdsh.Data = common.griddatasource.ToArray(); configGrid.DataSource = configdsh;
The result, is that I end up with two 'name' columns?
Hi Paul,
Thats strange.
Basically, when you create columns and add them to the DataSourceHelper, it looks at the columns already defined, and won't AutoGenerate any column that already exists.
I just tested it out, and it didn't duplicate the column for me. I assume you're not adding columns manually, correct?
-SteveZ
Steve,
Datasource helper:
public static customdatasourcehelper configdsh = new customdatasourcehelper();
This is the object that is populated multiple times as teh datasource:
public class VirtualMachineObject : NSObject { [Export("name")] public string name { get; set; } [Export("status")] public string status { get; set; } [Export("guestname")] public string guestname { get; set; } [Export("memory")] public string memory { get; set; } [Export("cpus")] public string cpus { get; set; } [Export("swapfile")] public string swapfile { get; set; } [Export("toolsversionstatus")] public string toolsversionstatus { get; set; } [Export("configStatus")] public string configStatus { get; set; } [Export("uuid")] public string uuid { get; set;} }
And the grid configuration:
public override void ViewDidLoad () { base.ViewDidLoad (); // Create a new gridview IGGridView configGrid = new IGGridView( new RectangleF(0,0,(this.View.Bounds.Width),this.View.Bounds.Height),IGGridViewStyle.IGGridViewStyleDefault); configGrid.AllowHorizontalBounce = true; configGrid.AlwaysBounceVertical = true; // Enable flexible width so that the grid feels its parents view configGrid.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; // Enable 2way Scrolling //Grid.common.gridconfig.enableScrolling (true, true, configGrid); // Configure grid theme configGrid = configuretheme.themegrid(configGrid); // Add gridview to the current view this.View.Add(configGrid); // Sort out custom column headers if (common.customcolumnheaders.Count != 0) { configdsh = common.configureheadertitles (configdsh, common.customcolumnheaders); } // Attempting to override column width configGrid.ColumnWidth = IGColumnWidth.CreateNumericColumnWidth (200f, 200f); // The following code is used to enable the filtering popup from the navbar button // Configure the popover control for the filter button. gridfilterpopup content = new gridfilterpopup(); content.callinggriddsh = configdsh; content.callinggridcontroller = configGrid; content.callingcustomcolumnheaders = common.customcolumnheaders; filterpopover = new UIPopoverController (content); filterpopover.PopoverContentSize = new SizeF(320,320); // Configure the navigation controller for this view // Configure a filter button UIBarButtonItem filterbtn = new UIBarButtonItem (UIBarButtonSystemItem.Action); filterbtn.Clicked += delegate { // If the popover is already showing from the bar button item, dismiss it. Otherwise, present it. if (!filterpopover.PopoverVisible) filterpopover.PresentFromBarButtonItem (filterbtn, UIPopoverArrowDirection.Any, true); else filterpopover.Dismiss (true); }; this.NavigationItem.SetRightBarButtonItem (filterbtn, true); // If we want the first column locked in place.. IGGridViewColumnDefinition col1 = new IGGridViewColumnDefinition ("name"); configdsh.FixedLeftColumns.Add (col1); // Add data to the grid configdsh.Data = common.griddatasource.ToArray(); configGrid.DataSource = configdsh; }
Hey Paul,
Glad you got it working!
One way, you could potentially do that, is to create your columns.
Then pull the first column from your ColumnDefinitions (delete it) and add it to the Fixed Columns.
Hmm.. interesting. Any chance you could provide a small sample at some point?
Sure.
Basically, using the code you provided, it would look like this:
// In this method, you're creating all of your columns (b/c you're not AutoGenerating) if (common.customcolumnheaders.Count != 0) { configdsh = common.configureheadertitles (configdsh, common.customcolumnheaders); }
// Remove the first column IGGridViewColumnDefinition col = configdsh.ColumnDefinitions [0]; configdsh.ColumnDefinitions.RemoveObject (0);
// Mark that column as fixed configdsh.FixedLeftColumns.Add (col);
And thats it.
Hi Steve,
Your answer includes something that caused me an issue originally (and led me to ask)
IGGridViewColumnDefinition col = configdsh.ColumnDefinitions [0];
the above line is not valid; I receive the following error:
'Cannot apply indexing with [] to an expression of type Monotouch.Foundation.NSMutableArray'
Sorry!
Thats what i get for sending code i didn't test :)
This should do the trick:
IGGridViewColumnDefinition col = new IGGridViewColumnDefinition(configdsh.ColumnDefinitions.ValueAt(0)); configdsh.ColumnDefinitions.RemoveObject (0); configdsh.FixedLeftColumns.Add (col);