ERLB save item index

ERLB save item index

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


esteban404 posted on Friday, January 23, 2009

I have a new ERLB scenario using CSLA 3.0.5 in a Winform. My use case matches the ERLB design intentions. I'm not using actual DB code yet, just a static id field for the ID and debug statements for each of the DP_XYZ methods to prove out the process.

First time new object works fine and the grid will also load all subsequent additions just by moving to the new row, but they do not get saved nor do I see the DP_Create fire according to the debug write, but the field is updated. Tracking the actions, I think it's because the index is not changed to let the BO know which item in the collection (row index?) is changing and needs to be saved. I couldn't find an example for it.

What am I doing wrong? Does the row index from the grid need to be given to the object so it can be saved?

TIA

_E

RockfordLhotka replied on Friday, January 23, 2009

The ERLB test/sample project is at Samples\CslaNet\vb\ERLBtest

I just checked it, and discovered that it hadn't been updated for 3.6. So I updated it and it works fine. You can see the current code in svn, or wait for the next 3.6.1 drop (probably later today).

esteban404 replied on Friday, January 23, 2009

I got the sample files. 3.6.0 framework and .NET 3.5 SP1. (I'm using 3.0.5 and do nothing with .Net 3.5 yet) When I attempted to compile the sample I rec'd an error:
Public Overrides Sub SaveItem(index As Integer)' cannot override 'Public Overridable Function SaveItem(index As Integer) As Root' because they differ by their return types.

I changed it to Public Overloads... and got it to compile, but I still don't get where I need to get the index from. There appears to be a hard coded index of 3 under Button1 ("Remove S"). I don't think hard coding is what I need to do. something is mixed up in my brain.

I'll check to see if there's a change in the samples later, but right now it's not helping me understand how to get the grid to save added items beyond index 0 of the collection after they are added successfully and the row looses focus.

I see I can get the index by using the object using this method:
list.SaveItem(list.IndexOf(MyObject item));

Is that the way to go about it? i thought the data grid view and the binding source would work together differently. Or am I barking up the wrong tree and I should be using the index of the binding source?

I'll keep trying...

_E

RockfordLhotka replied on Friday, January 23, 2009

Maybe I don't understand what you are trying to do?

You shouldn't have to manually deal with item indexes at all when an ERLB is
bound to a datagrid. The whole point of ERLB is that it automatically
responds to the events of the datagrid via data binding so you don't do
anything extra at all.

The primary purpose of ERLBtest is to establish that a user can add, edit
and delete items in the left-hand grid, which is bound directly to the ERLB.
If you watch the output window in VS you'll see a lot of various methods
that are invoked as this happens, to prove that new items are inserted,
existing ones updated or deleted, etc.

I thought that's what you were after - the ability of a user to just add new
items by moving to the bottom row of a grid? Such an item is automatically
inserted as soon as the user leaves that row (assuming no validation rules
are violated, etc).

Rocky

-----Original Message-----
From: esteban404 [mailto:cslanet@lhotka.net]
Sent: Friday, January 23, 2009 2:06 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] ERLB save item index

I got the sample files. 3.6.0 framework and .NET 3.5 SP1. (I'm using 3.0.5
and do nothing with .Net 3.5 yet) When I attempted to compile the sample I
rec'd an error:
Public Overrides Sub SaveItem(index As Integer)' cannot override 'Public
Overridable Function SaveItem(index As Integer) As Root' because they differ
by their return types.

I changed it to Public Overloads... to got it to compile, but I still don't
get where I need to get the index from. There appears to be a hard coded
index of 3 under Button1 ("Remove S"). I don't think hard coding is what I
need to do. something is mixed up in my brain.

I'll check to see if there's a change in the samples later, but right now
it's not helping me understand how to get the grid to save added items
beyond index 0 of the collection after they are added successfully and the
row looses focus.

I see I can get the index by using the object using this method:
list.SaveItem(list.IndexOf(MyObject item));

Is that the way to go about it? i thought the data grid view and the binding
source would work together differently. Or am I barking up the wrong tree
and I should be using the index of the binding source?

I'll keep trying...

_E

esteban404 replied on Friday, January 23, 2009

>> I thought that's what you were after - the ability of a user to just add new
>>items by moving to the bottom row of a grid? Such an item is automatically
>>inserted as soon as the user leaves that row (assuming no validation rules
>>are violated, etc).

That's precisely what I'm trying to do, it's ideal for this use case. The only difference might be the insertion of data values in the grid when the InitNewRow is executed by the grid (XtraGrid). Those values are then used to construct the new object I'm working with. I'm going to remove these new values to see if it works.

In its current form, when running the app DP_Create() runs fine, but there is no evidence the new items are being saved/inserted. If I place a break at
public override void SaveItem(int index)
{ base.SaveItem(index); }
The index is always 0 for every item. So if i've added 5 new items to the grid, the create fires fine, but when i leave the row, the Insert/Update do not fire except if it's the first row I've added. It's like the binding source is stuck. I read there should be nothing further to do, that was the ideal thing for this scenario.

If I leave that first row, insert some more data into the grid, come back, make a change to that first record, the Update fires as expected, but none of the other rows in the grid do that in the same circumstance.

Help more? I'm sure it's just an implementation snafu of mine, but I don't see it.

Thanks

_E

RockfordLhotka replied on Friday, January 23, 2009

What version of CSLA again? 3.0.x?

I think that version still required a GetIdValue() to return a unique value for each item in the collection - including new items. Failure to provide a unique id value from the moment the object is created would cause nasty issues with any collection type, including ERLB.

esteban404 replied on Monday, January 26, 2009

I recreated a simple object from the 2.1 handbook. It works fine for the included Windows grid, XtraGrid, PROVIDED a record is returned by the GetList() method. Since I am providing a default row constructor, that was an easy enough solution for me, but in some cases, it does need to be a blank record. I just added a NewList() method to the ERLB class so the UI can add it when initialized and get started straight away. I'll keep the decremeting "lastID" field to manage the creation. That seems to work great.

Thanks for the input!

_E

rsbaker0 replied on Monday, January 26, 2009

This may or may not be relevant, but I've found the XtraGrid to indeed be quirky, but part of that is (apparently) my own doing because my objects implement ICustomTypeDescriptor.

After much consternation, I found that the XtraGrid would malfunction when attempting to do data entry in an empty list unless I implemented ITypedList on the list class. However, it works perfectly if there is already at least one item in the list. I reported this as a bug to DevExpress, and they claimed it's a built-in limitation of the framework. A simple implementation of ITypedList took care of it.

 

esteban404 replied on Monday, January 26, 2009

That's exactly the same thing I found. I didn't implement ITypedList to get it to work, but that sounds simpler. DevExpress hasn't responded yet, but I did send a sample project to show the issue. I may try implementing ITypedList since this development is still in the kick-it-around phase.

Thanks rsbaker0!

_E

esteban404 replied on Tuesday, January 27, 2009

I implemented ITypedList, but it behaved worse and required a public constructor for the list. Strange. I may not have implemented the interface correctly, but after running it, I couldn't insert default values anymore. Hmm.

RockfordLhotka replied on Friday, January 23, 2009

I'd try your collection against the standard Microsoft datagrid. That'll
help ensure that your object isn't the culprit. If that works, then you know
it is some non-standard behavior of XtraGrid and you can work to debug the
grid's interaction with the collection.

Rocky

Copyright (c) Marimer LLC