StrataFrame Forum

Slow Listview Requery

http://forum.strataframe.net/Topic22688.aspx

By Jared Ewald - 4/10/2009

Hi to all. I am populating a listview from a business object using the CopyDataFrom(BusinessLayerBase,BusinessCloneDataType) method. This business object can have up to about 1600 rows in it. The issue here is that the lstview.Requery() method that is populating the listview from the rows in the business object is taking a long time. I should mention that this listview is on a tab that is not initially shown. The requery is really quick until the tab with the listview is shown the first time, even if it is hidden after that. (The listview is filled and queried on the navigate method of the primary business object.)



The StrataFrame source code where the slowness occurs is during the following for loop in the PopulateListView function in ListView.vb:



For lnCnt = 0 To loBO.Count - 1

'-- Move to the row we need

loBO.MoveAbsolute(lnCnt)



'-- add the item to the list

Me.Items.Add(CreateListViewItem(loBO))

Next



Does anyone have any ideas?



Thanks,



Jared
By Trent L. Taylor - 4/13/2009

Well, in the code snippet you gave would be all of the slowest possible ways to enumerate a BO and create a list view item (though I didn't see the code behind your CredteListViewItem).  In this example, you are manually populating your ListView which requires a bit of optimization to prevent rendering and callbacks.

When manually populating a ListView, you will want to call the BeginUpdate() prior to loading:

'-- Prevents events and rendering (will dramaticaly improve loading)
MyListView.BeginUpdate()

'-- Populate Here

'-- When completed, end the update otherwise the list will not act right
MyListView.EndUpdate()

Next, when you enumerate a BO, use the enumerator:

For Each bo As MyBOType in MyBoInstance.GetEnumerable()
   '-- You now have a strong-typed reference and pointers, etc. will all be handled
   '    from within the enumerator
   MyListVIew.Items.Add(CreateListViewItem(bo))
Next

But the best way would be to let the ListView populate for you as it already handles all of this.  Ust the PopulationDataSoruceSettings of the ListView to manage this for you.