Ihave an UltraGrid which is populated form a collection of Custom objects where each object in the collection is a custom object called BLDepartment which itself contains properties of custom objects within it. The code to do this is:
this.AllDepartments = BLDepartment.GetDepartmentsFromManagerPersonId(BLPerson.LoggedOnPerson.PersonId);this.bLDepartmentBindingSource.DataSource = AllDepartments;this.bLDepartmentUltraGrid.DisplayLayout.LoadStyle = Infragistics.Win.UltraWinGrid.LoadStyle.LoadOnDemand;this.bLDepartmentUltraGrid.DisplayLayout.MaxBandDepth = 3;this.bLDepartmentUltraGrid.DataSource = this.bLDepartmentBindingSource;
The code hangs for a very long time (about 3 minutes) on the last line. I assume this is because as the grid is binding to the collection, it is going into evey public property of every BLDepartment object in the collection. If this is the case is there a way to stop this hapenning and so improve performance ?
Any help greatly appreaciated.
John
Hi John,
jvinnell said:I assume this is because as the grid is binding to the collection, it is going into evey public property of every BLDepartment object in the collection.
No, I don't think so. The grid doesn't do that. I will loop through all of the rows at the root level, but it's not going to access every property. My guess would be that your MaxBandDepth is somehow getting reset and the grid is, in fact, walking down beyond level 3. Try checking the MaxBandDepth property after you set the DataSource to see if it's still set to 3.
If that's not the issue, then I'll need more information. If you could post a small sample project demonstrating the issue, that would be the best thing and I could tell you exactly what's taking so long.
If not, then the structure of the BLDepartment would be helpful. Also, the number of rows in the list would be good to know.
Mike,Thanks for pointing me in the right direction. When I set MaxBandDepth=2 I see 4 bands when I look in the designer and performance is fine. When I set MaxBandDepth=3, which I need to do to get one of the bands I need, I see 47 bands in the designer and performance is bad.
I actually only need 1 parent and 2 child bands so is there some way to remove the unwanted 44 bands or stop them being read insome way ? Or only bind the 3 collection properties in my BLDepartment object that I need to the grid.
Thanks John
Your data source is recursive. A BLPerson contains a BLProjectAccess, which contains a BLPerson, which contains a BLProjectAcess, etc. So even if the actual data isn't recursive, the data structure is.
There's no way to set a MaxBandDepth on only some particular tables or relationships. It's all or nothing. So maybe what you could do is set MaxBandDepth to something like 5 and that would not limit the rest of your data too much.
The only other alternative would be no to bind the grid directly to your data source, but to create some sort of intermediary object, such as UltraDataSource, which defines the structure you want in the grid. This would require some code to handle the interaction between the intermediary and the 'real' data source, of course.
Hi Mike,
I have taken your advice and set the DataSource to “None” in the designer and then setting everything at run time so I now have a workaround for this. I would however like understand a bit better what is actually happening as I think I have an issue with my classes and the way they are binding to the grid. Let me know if you want me to raise another post.:
My BLDepartment class contains a Collection of BLPerson, BLPerson contains a Collection of BLProjectAccess and BLProjectAccess class contains a property of type BLPerson. When I bind the BLDepartment object (which is my parent) to the DataSource it adds the Collection of BLPerson and the Collection of BLProjectAccess as child bands to the grid, which is what I want but then seems to traverse down the BLPerson property in the Collection of BLProjectAccess which means I get 2 BLProjectAccess child bands. I appear to be getting some kind of recursion in the binding which eventually ends up with 40 or so bands in the grid when all I want is BLDepartment,BLPerson and BLProjectAccess.
Is there any way to stop this happening. Somehow I want a band depth of 3 but only for collections that tier up to the BLDepartment parent.
Well, it's no mystery why this loses the grid layout. Setting the DataSource to null will do that, since the datasource has no columns in it and all of the grid columns will get blown away.
Why this affects the performance is a bit of a mystery. My best guess is that your grid has already created a whole lot of bands at design-time and htose are getting carried into run-time. Maybe you don't actually have 40+ bands in the first three level after all, but instead those extra bands are just residual bands that exist deeper in the hierarchy at design-time. If that's true, then instead of setting the DataSource to null at run-time, you are better off just resetting the grid's DataSource in the designer and then it will already be null at run-time. You still won't be able to use the designer for setting up your layout, but at least you won't be binding the grid 3 times.
After some more investigation/playing/surfing using MaxBandDepth=3 and the code below appears to fix the problem and turns and 3min delay to display the data into a 2sec delay. The key thing seems to be the 1st line i.e setting the grids datasource to null. One downside is that I seem to loose any grid settings I changed in the designer e.g hidden bands/columns but I can do that in code after.
this.bLDepartmentUltraGrid.DataSource = null;this.bLDepartmentUltraGrid.DisplayLayout.LoadStyle = Infragistics.Win.UltraWinGrid.LoadStyle.PreloadRows;this.bLDepartmentUltraGrid.DisplayLayout.MaxBandDepth = 3;this.bLDepartmentBindingSource.RaiseListChangedEvents = false;this.bLDepartmentBindingSource.DataSource = AllDepartments;this.bLDepartmentUltraGrid.DataSource = this.bLDepartmentBindingSource;this.bLDepartmentBindingSource.RaiseListChangedEvents = true;
I can't say I fully understand why this works so Mike if you can explain it the please do and thanks for your help which helped my investigations
Hi Mike,Thanks. It looks like the UltraDataSource might work and I have taken a look at the Virtual Mode sample. 2 questions:1. Will this result in the bands in the grid having the same type as they do now as on a double click I do things like if (e.Row.ListObject is BLDepartment). If not then I think I'm a bit stuck ulsess you know of a way I can bind the grid to certain properties of my BLDEpartment object2. Is there an easy way to populate the the UltraDataSource with the properties from my BLDepartment object. I notice that the example uses UltraDataSource1_InitializeRowsCollection and ultraDataSource1_CellDataRequested but I'm not bothered about LoadOnDemand so am happy to load all the dfata at once.
The main reason that this is hapenning is that my BLDepartment object contains a collection of BLPerson objects and BLPerson contains a lot of other properties one of which I need which is why I need MaxBandDepth=3 but unfortunately by setting it to 3 I also get the other 40 or so.
I don't suppose there is some way I can leave MaxBandDepth=2 which gives be my Parent BLDepartment Band and Child BLPerson band (plus 2 others which I can hide) and then force the BLPerson band to display a "+" expandable sign next to each row which when clicked on goes and gets the child data it needs on the fly and displays it ? If there is a way to do this then don't bother answering the 2 points above