We have a custom BLPerson object which contains a number of child object such as BLUserid We then do the following BLCollection<BLPerson> ALLPeople=new BLCollection<BLPerson> ALLPeople=BLPerson.GetAllPeople(); bLPersonBindingSource.DataSource =AllPeople; blPersonUltraGrid.DisplayLayout.MaxBandDepth = 4; this .blPersonUltraGrid.DataSource = this.bLPersonBindingSource;
Basically we have ALLPeople which is a collection of BLPerson which we bind to a grid.
We notice that when we trace into the line bLPersonBindingSource.DataSource =AllPeople; the code is going into each of the child objects for each of the BLPerson objects in the ALLPeople collection and populating this child object. This causes a significant performance.
We notice that if we comment out the bLPersonBindingSource.DataSource =AllPeople; line and set the grids datasource directly i.e this .blPersonUltraGrid.DataSource =ALLPeople then the problem doesn't ocurr however I have read that it is not good to set the datasource directly.
Any help on the best way to do this would be appreciated
Thanks John
Hi John,
I'm not sure I follow you. Whether you use a BindingSource or not, the grid has to read the values of the cells for display. So it should be accessing every public property of every item in the collection. It has to in order to populate the cells in the grid.
Mike, Thanks for the reply.
We have managed to improve performance considerably by setting the bLPersonBindingSource.RaiseListChangedEvents = false and then switching it back on again after
BLCollection<BLPerson> ALLPeople=new BLCollection<BLPerson> ALLPeople=BLPerson.GetAllPeople(); this .bLPersonBindingSource.RaiseListChangedEvents = false ; bLPersonBindingSource.DataSource =AllPeople; blPersonUltraGrid.DisplayLayout.MaxBandDepth = 4; this .bLPersonBindingSource.RaiseListChangedEvents = true ; this .bLPersonBindingSource.ResetBindings( false ); this .blPersonUltraGrid.DataSource = this .bLPersonBindingSource;
I guess that makes sense. There's no point in raising the events if the grid is not bound and therefore no one is listening.