StrataFrame Forum

Binding to an editable grid?

http://forum.strataframe.net/Topic1889.aspx

By Andria Jensen - 7/19/2006

Is there any way to bind to the enhanced list and also have it be editable so that users can make changes directly to the grid itself?  If not with the enhanced list is there a way to do it with the DevExpress grid control?
By Trent L. Taylor - 7/19/2006

The Enhanced list is a grid modified for list-like interaction.  This is to produce a behavior more like the ListView within the standard StrataFrame control collections.  If you want to allow editing within a grid, then you will need to use the DevExpress grid.  When using a grid you will need to use the CurrentDataTable or CurrentView of the business object as the data source. 
By Andria Jensen - 7/19/2006

Ok, is there a way to have it accept changes made by the user in the grid and save them to the bound data source?  Or is this just something that I'll have to do manually somehow?
By Trent L. Taylor - 7/19/2006

You will have to save the changes back to the database yourself.  You will need to call the Save on the BO before the changes are committed to the database.  Is this what you mean?  The same is true for any other StrataFrame control, it requires a Save before any change is committed.
By Andria Jensen - 7/19/2006

That's kind of what I'm asking. I guess what I mean is does it work like the other SF controls which you can just set to a BO and they automatically update as you change the contents using the Edit and Save events.  Will it work along with something like the Maintenance Toolstrip?
By Trent L. Taylor - 7/19/2006

StrataFrame uses an ADO.NET data table internally in a BO to store the data.  If the internal data table (CurrentDataTable, CurrentView, or CurrentRow) changes any of the contents either manually or through a control of some sort, the BO will know that it is dirty and requires an update.

For example, the code below changes the field through the weak typed ADO.NET data table instead of using the strong-typed properties of the BO.

MyBO.CurrentDataTable.Rows(0).Item("my_field") = "Testing"

This will change the contents of the field and the business object will still know that a save is required just as though it had been changed through a strong-typed property or an SF control.

If MyBO.IsDirty Then
     MyBO.Save()
End If

So if you use ADO.NET data binding to the DevExpress grid, the BO will still function properly.  But you will still be required to manually call the Save() method on the BO to save commit the changes back to the server.

By Andria Jensen - 7/19/2006

Great!  Thanks, I think I have something working now.  This will be great for what I'm trying to do.
By Andria Jensen - 7/19/2006

Everything seems to be working fine, except for when I add a new row to a blank table.  It gives me an error on my BO.Save method saying 'An error occured while saving data to the server' and to check the InnerException.  Well basically it looks like CurrentRowIndex is set to -1 even though there is a record in the BO.  The actual error message is this:

{"The CurrentRow could not be evaluated because the CurrentRowIndex is out of range.  Business object record count: 1.  CurrentRowIndex: -1."}

Any idea what would cause this?  I can add records to a table that already has records, but not to a blank table. 

By Trent L. Taylor - 7/21/2006

Andria,

Sorry for the slow response.  I guess I missed this post.  At what point are you getting the error message?  Can you give me a code snippet?

By Andria Jensen - 7/21/2006

That's okay, I've worked through it and have it working now.  Thanks though Smile
By Trent L. Taylor - 7/21/2006

I am glad you got going.  Sorry again. Blush