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.  [ 6 posts ] 
Author Message
 Post subject: binding data, DataGridView
PostPosted: Wed Apr 09, 2008 1:51 pm 
Newbie

Joined: Wed Apr 09, 2008 11:16 am
Posts: 4
Hi,

I'm new to nHibernate and have some questions to use it with .Net Winforms.

In my application I use
Code:
session.CreateCriteria
to query data which works good. But I use some DataGridView controls which do not always display all properties of the loaded class. If I bind the returned IList to the control I see all columns of the table.
Can I filter the column list as I can do it in SQL's Select statement?
If I use
Code:
session.createSQLQuery
there must be a object which contains the specified columns.

I use
Code:
column.visible =false
from datagrid which works so far and hides for example the id column. But is it possible to rename the columns. I have a database column "car" and want to replace it with some translated string. I don't see any way to do this with NHibernate, because I lose the object behind. In Sql I write "Select car as Auto from ...".

When the IList is bound to the control it is not possible to rename the columns any more. How can this be done without copying the IList to a new generated Datatable?


Thanks.


Top
 Profile  
 
 Post subject: foreign key projection
PostPosted: Wed Apr 09, 2008 3:42 pm 
Newbie

Joined: Wed Apr 09, 2008 11:16 am
Posts: 4
Hi,

i think the solution may go something like this?

Code:
criteria.SetProjection(Projections.ProjectionList()
                     .Add(Projections.Property("car"), "Auto")...



But my Poco object has a foreign key. If I add this to a projection I get an NHibernate.AdoException. If I don't add it to the projection I don't get my special instance of the poco object. I just get an array of objects.

Any idea? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 2:59 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Afaik, you can not rename the columns, but you can set a new header text anytime you want.

Personally, I woulcn't put the functionality for column naming and display in the data access layer. I can think of some other approches:

- define a template which contains names, display order, visibility, maybe format strings and apply that to the grid. This gives you the possibility to use different languages for naming (if you have to) or store the settings per user

- use attributes on the properties which define the display name and the visibility

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 5:55 am 
Newbie

Joined: Wed Apr 09, 2008 11:16 am
Posts: 4
Thanks for the reply.

If I understand you right, data binding to a grid makes no sense most times because normally I will not see all columns in the grid with their database column name.
My database is in english, the GUI should be in german. It's a small application so changing the language is not intended in the near future.

Afaik there is no template for columns in datagridview. Just for rows. I can create a datatable with the used columns and bind it to the grid but in this case I have to copy all data in a loop to the datatable. This is a big overhead and in this case I lose the object binding in the grid.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 6:21 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can set AutoGenerateColumns to false and add the columns yourself (which is what we do and what I meant with column template). You also have to specify the "DataPropertyName" on the column. Then you can bind to that grid as if you use automatic column creation.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 11:29 am 
Newbie

Joined: Wed Apr 09, 2008 11:16 am
Posts: 4
That's a working solution.

Thanks for your advice!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.