These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to sort a DataGridView with Iset as datasource ?
PostPosted: Thu Jul 26, 2007 4:14 am 
Newbie

Joined: Wed May 30, 2007 4:00 am
Posts: 4
Location: Dijon, Bourgogne, France
Hibernate version: 1.2.0.4000
Mapping documents: really usefull here ?
Name and version of the database you are using: SQL Server 2005

Hi everyone, I'm using the CreateCriteria Method to create an IList.
Then I cast this IList to an ArrayList which is finally specified as datasource to a DataGridView. Clearly :
Code:
ArrayList liste = (ArrayList)this._session.CreateCriteria(typeof(MyWonderObject)).List();
dataGridView1.datasource=liste


Then the list is displayed correctly (that is not so bad) but it is impossible to sort it on another Column with a clic on a ColumnHeader.

Could you explain me why? How could I give an Iset as a datadource AND keep the datagrid's sort functionalities?
P.S.: MyWonderObject is already Implementing Equals() and compareTo() methods.
Thanks in advance.

Kerseub

_________________
Ouch! Not on the Head!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 11:39 am 
Newbie

Joined: Tue Jul 24, 2007 3:27 pm
Posts: 3
The problem is, when you are initializing DataSource property with a IEnumerable, ASPNET can't guess, how expensive is the iteration.

It could actually be lazily fetching the rows from database while iterating, and it can be the case with NHibernate lazy loading.

ASPNET can't make the hard decision to load and cache your IEnumerable in internal collection just to enable sorting.

When you are using a disconnected object instantiated in memory, such as an ArrayList or a DataSourceView everyting is ok, but you lose your lazy behavior.

You can wrap your select method in ObjectDataSource control, and have NHibernate load only a small part of the list for one page on sorting request:

http://msdn2.microsoft.com/en-us/library/sa88ktts.aspx


Top
 Profile  
 
 Post subject: Re: How to sort a DataGridView with Iset as datasource ?
PostPosted: Thu Jul 26, 2007 12:27 pm 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
kerseub wrote:
Hibernate version: 1.2.0.4000
Mapping documents: really usefull here ?
Name and version of the database you are using: SQL Server 2005

Hi everyone, I'm using the CreateCriteria Method to create an IList.
Then I cast this IList to an ArrayList which is finally specified as datasource to a DataGridView. Clearly :
Code:
ArrayList liste = (ArrayList)this._session.CreateCriteria(typeof(MyWonderObject)).List();
dataGridView1.datasource=liste


Then the list is displayed correctly (that is not so bad) but it is impossible to sort it on another Column with a clic on a ColumnHeader.

Could you explain me why? How could I give an Iset as a datadource AND keep the datagrid's sort functionalities?
P.S.: MyWonderObject is already Implementing Equals() and compareTo() methods.
Thanks in advance.

Kerseub


The datagridview only supports sorting datatables or dataviews if i recall correctly. Create a List based on your ISet (just pass it to the constructor... it implements IEnumerable so the List constructor will accept it) and then you can use Mark Brooks' DynamicComparer to easily (and very efficiently) sort the list based on the sortexpression of the DataGridView.

You can find an example of how to use the DynamicComparer here:
http://ralinx.wordpress.com/2007/07/02/ ... f-objects/

it provides very fast sorting and you don't have to do anything for it... it's very nice. All you need to do is implement the sort method of the DataGridView (or is it the sort method of the ObjectDataSource... i'm not sure on that one)... you can simply pass the sortexpression from the DataGridView to the DynamicComparer and the list will be sorted nicely.

_________________
Davy Brion
http://ralinx.wordpress.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.