DataGridView - Saving when a bound entity has a Collection type property.

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 18-Jun-2007 11:23:40   

I have an object called Issue which has a property of type PageCollection which contains Page object which have a Number property. Although the collection supports multiple Page objects to be associated with a single Issue object, I'm trying to set up a simple DataGridView which binds through a binding source, to the IssueCollection object.

I have a column called PageNo in the grid which I'd like to save / update when the row changes. Ideally I'd like to embed a UserControl within a cell in the grid so I could add an "Add" / "Remove" buttons, a text box and a list box to support clients adding page nos which are then saved in the Pages properties by adding new Page objects. However for now I just want a simple solution.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Jun-2007 10:50:43   

I have a column called PageNo in the grid which I'd like to save / update when the row changes. Ideally I'd like to embed a UserControl within a cell in the grid so I could add an "Add" / "Remove" buttons, a text box and a list box to support clients adding page nos which are then saved in the Pages properties by adding new Page objects.

What have you tried so far, and what was the stopping issue?

However for now I just want a simple solution.

What do you mean by a simpler solution, something else than what was described above?

Posts: 254
Joined: 16-Nov-2006
# Posted on: 19-Jun-2007 13:00:21   

I can't get this to work by setting the DataPropertyName of each of the bound columns in the DataGridView because it isn't a direct property of the Issue entity. e.g. the Issue entity is comprised of the following properties

Name - String Prioirty - PriorityId ( drop down Pages - PageCollection

I presume I need to use custom data binding with an event of the DataGridView / BindingSource or some change to the LLBLGen entity but not sure which.

The simpler solution in that I only want to specify a single Page object bound to the Pages Collection. e.g. so a user just enters 10 as the Page no, and a Page object with a Number property of 10 is created and added to the collection. The more complex solution would allow a user control to be emdedded as a column with buttons in the control to support maintaining multiple pages to reflect the PageCollection type.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39912
Joined: 17-Aug-2003
# Posted on: 19-Jun-2007 21:00:20   

what exactly do you mean by this:

Although the collection supports multiple Page objects to be associated with a single Issue object, I'm trying to set up a simple DataGridView which binds through a binding source, to the IssueCollection object.

Perhaps I miss something, but I don't quite follow this.

Also, these scenario's can get complex really quickly, so if you have an example form which illustrates what you want (to some extend), it would be great as from the posts you posted, I don't fully understand what you're trying to accomplish. Binding a collection to a grid is pretty straight forward, so I don't think that's the bottleneck so it must be something else. wink

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 19-Jun-2007 21:04:08   

It's essentially binding a collection from an entity within a collection bound to the grid.

i.e. if we consider the grid is bound to an IssueCollection, therefore each row represents an Issue entity. Each Issue entity has a number of simple properties e.g. Name, Date. These can easily be represented by simple bound columns. However we also have a property which is of type PageCollection. I would like to bind a single column to this collection so that the numeric value entered in the column gets bound to this collection by

a) If a new row is being created a new Page object is created and it's Number proprety set to the value in the cell called PageNo.

b) If an existing row is being edited, the existing Page object in the PageCollection is updated to reflect the value in the cell e.g. Number property is changed from 10 to 20

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39912
Joined: 17-Aug-2003
# Posted on: 20-Jun-2007 22:51:13   

MattAdamson wrote:

It's essentially binding a collection from an entity within a collection bound to the grid.

i.e. if we consider the grid is bound to an IssueCollection, therefore each row represents an Issue entity. Each Issue entity has a number of simple properties e.g. Name, Date. These can easily be represented by simple bound columns. However we also have a property which is of type PageCollection. I would like to bind a single column to this collection so that the numeric value entered in the column gets bound to this collection by

a) If a new row is being created a new Page object is created and it's Number proprety set to the value in the cell called PageNo.

b) If an existing row is being edited, the existing Page object in the PageCollection is updated to reflect the value in the cell e.g. Number property is changed from 10 to 20

Ah!

Ok, that's not directly possible, IList implementing types (thus also the collection) can't be represented by a column in a grid. So you have to add a new property to IssueEntity in a partial class which is the property which will be reflected in the column. The get/set of that property then do what you're trying to do with the column bound to the collection simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 20-Jun-2007 23:10:13   

Could this not be done within the client win forms code though using a custom binding event either on the entity, binding source or datagridview?

As this property would really only be useful for presentation tier code I'd rather not put it in the business object / data access tier.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39912
Joined: 17-Aug-2003
# Posted on: 21-Jun-2007 10:12:01   

MattAdamson wrote:

Could this not be done within the client win forms code though using a custom binding event either on the entity, binding source or datagridview?

As this property would really only be useful for presentation tier code I'd rather not put it in the business object / data access tier.

THat's the state of affairs with databinding in .NET: an IList implementing property is seen as a collection which is a sub-band of a current grid band. Also, if you want a property to appear only in the PL, you can't or you have to write a wrapper/proxy.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 21-Jun-2007 11:49:48   

Thanks, but I can't believe theres not an event which will handle this in a better way to avoid having to write a wrapper / add an additional property, it's just we don't know what it is rage

When I find it I'll update this thread, in the meantime we can close it.