DevExpress XtraGrid ChildCollection, AddNewRecord

DevExpress XtraGrid ChildCollection, AddNewRecord

Old forum URL: forums.lhotka.net/forums/t/5380.aspx


Jurjen posted on Wednesday, September 10, 2008

Hello,


I'm using DevExpress XtraGrid (8.2.1) in my windows-application and am having some problems with child-collections. Editing is working just fine, but when adding a new child to the childcollection using the 'NewItemRowPosition' so the new record will be inserted by the grid, strange things happen, the first keystroke (or selected date in dateEdit) is discarded, while adding items in a similar fashion to a EditableRootCollection works just fine.

I was just wondering if anyone here had maybe solved this problem already, so I won't have to. Big Smile <img src=" src="/emoticons/emotion-2.gif">


TIA,
Jurjen.

andy replied on Thursday, September 11, 2008

Hi TIA,

I just started testing xtrgrid for my new project.
Would be interested to know all the sharp edges that you may have using the component.:)

Andy

Jurjen replied on Thursday, September 11, 2008

TIA = Thanks In Advance.... :-)

Well Andy,

I have subclassed all DevExpress controls that I use in my project, which is (I think) a good way to get uniformity on controls within a project. Except for the problem as explained in my message I'm not encountering any real problems, I find that it works just fine.

Jurjen

andy replied on Thursday, September 11, 2008

I just learned a new acronym today! :)

I just love their GUI.  Their skinning looks and feels UI feature just rocks. 
One question, where did purchase your dx component.
I notice componentsource offers a cheaper deal.
Not sure I will get the same support level for it.
Tks for the tip.

Andy

 

Curtmantle replied on Thursday, September 11, 2008

The DevExpress components are excellent by-and-large. The documentation sucks a bit which leaves you battling with trial and error a lot of the time - but they are extremely good components.

I haven't encountered the problem mentioned but that might be because I go about things differently in terms of design and use. The one thing you do need to remember when you want to add rows via a grid is to override the AddNewCore function in your BindingList derived class. Apart from that I haven't had any serious problems... although it's early days in my project!


Jurjen replied on Saturday, September 20, 2008

Well, as it turns out the problem was not with Devexpress controls and also no with Csla but with code in my subclasses wich inherit from csla. When adding a child to my childcollection I set the foreign key to the parent during the AddNewCore(), here the value for property fkOrderId is set, wich raises the propertychanged event, when this 'SetForeignKey' code is commented out, the problem goes away.

 

Jurjen

rsbaker0 replied on Saturday, September 20, 2008

Is this a master-detail grid editing scenario? We use the DevExpress suite also -- I'm just trying to envision the particular U/I design that is leading to your problem.

In our case, the XtraGrid works great with an editable root, but if that root has children and you use a master-detail grid, the ERLB saves the root item when you click on a child row, effectively orphaning the child items. We haven't solved this and so don't use this feature except for read-only scenarious.

Jurjen replied on Saturday, September 20, 2008

No it's not. It's a root object with a child collection, only the child-collection is bound to the XtraGrid.
But it's working fine now..

In your scenario, what type of datatype do you use for your keys, Guid or Int ?
I use guids, and when a new child is created I call a method called 'SetForeignKey(businessobject parent)' on the child, thereby setting it's foreign key to the parent, that way, when the child-collection is saved, no 'orphans' are created. If you use Int as foreign key, then you should call Setforeignkey on new children after you've saved the parent and know what the Int value the database assigned to the Primary Key or ID-field, so it can be assigned to the foreign key field of the children.

I think this should also work in a Master-Detail grid.

Jurjen

rsbaker0 replied on Saturday, September 20, 2008

My keys are int (autonumbering in various flavors, from sequences in Oracle, IDENTITY in SQL Server, autonumber in Access).

I'm currently using CSLA 3.0.x, and since I'm responsible for doing all the child object saving in this version of CSLA (at least I think that is the case ;) , I was setting the parent foreign key of child objects when the parent object is saved.  Each BO saves itself first, then traverses child objects and saves them if they are new/dirty and updates their parent foreign key value automatically.

For a child list, I wasn't using an editable root list but instead a BusinessListBase derived class, so the grid shouldn't "save" those objects.

Copyright (c) Marimer LLC