Question

I have an Infragistics Ultragrid that is being used to display a list of attributes. Sometimes the attribute is an array so I am adding a sub row for each element so the user can optionally expand the row showing the array attribute and see all the element values.

So for each element I use:

var addedRow = mGrid.DisplayLayout.Bands[1].AddNew();

which if I have 300 elements gets called 300 times and takes around 9 seconds (I have profiled the application and this call is taking 98% of the elapsed time)

Is there a way to add these sub rows more efficiently?

Was it helpful?

Solution

I know I'm late with an answer, but hopefully someone can use my answer anyway. Whenever I need to set rows and subrows for ultragrid, I simply set the datasource by using linq and anonymous types to generate the propper collection. say you have a list of persons (id, Name), and a list of cars (id, CarName, and OwnerId (personId)) now you like to show a gridview showing all persons, with an expandabel subrow providing which cars they own. simply do the following.

List<Person> persons = GetAllPersons();

List<Car> cars = GetAllCars();

grid.DataSource = persons.Select(x => new {x.Id, x.Name, Cars = cars.Where(z => z.OwnerId == x.Id).ToList()}).ToList();

Note the anonymous type I make, this will generate a list of objects having an id, Name, and a collection of cars. Also note that I call the ToList method twice in the last line, this is necessary in order to get ultragrid to bind properly.

Note further more that if you need to edit the gridview, the above method migth not be sufficient, as the ultragrid needs an underlaying datasource for modifying, and I dont believe that this will cope. BUT on the internet you'll find some extensions that can copy a Linq collection into a DataTable, doing that and then you should also be able of editing the grid.

I have often used the above method and it performs extremely well, even for huge collections.

Hope this helps somebody

OTHER TIPS

you might want to use ultraGrid1.BeginUpdate(); and ultraGrid1.EndUpdate(true); to stop screen from repainting. made huge performance benefit for my app.

Also in my case I was populating nearly >10,000 rows, so have used UltraDataSource

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top