EditableRootList and BusinessBase

EditableRootList and BusinessBase

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


AndyW posted on Thursday, December 03, 2009

I have a problem with my implementation of EditableRootList.

I have an EditableRootList (StockList) with a collection of BusinessBase (StockItem) and bound to a Windows form Grid. I can update the grid successfuly, however I want to be able to double click on a grid item and launch in a new form, this form is a more detailed form, whereas the grid is more of a snapshot with only a set amount of fields updatable.

I am passing the current grid item to my form like this

using (Forms.StockEntry stockEntry =
new Forms.StockEntry((Business.StockItem)bindingStockList.Current))
{
stockEntry.ShowDialog(this);
}

And on my form the code looks like this

Private Business.StockItem _sd;

public StockEntry(Business.StockItem sItem)
{
InitializeComponent();

_sItem = sItem;
bindingSourceStockItem.DataSource = _sItem;
}


Now I am not sure if that is the best way to pass the current selected grid item to a form, but it works.

I can now change data on the form and so on, and when I save, it is automatically reflected in the grid, great. However if I cancel the edit on the form and close the form the new information updates to the grid and does not perform a .CancelEdit. I am calling CancelEdit myself.

I cannot work out why, any pointers would be very appreciated.

Thanks
Andy

RockfordLhotka replied on Thursday, December 03, 2009

Sadly this is more complicated than you'd hope due to the way WinForms data binding works...

An object can be bound to one thing at a time. The object is bound to the datagrid, and you are then trying to bind it to the dialog, and you can't do that. You need to unbind the object from the datagrid first (which really means unbinding the entire list from the datagrid) so you can display it in the dialog...

rxelizondo replied on Thursday, December 03, 2009

RockfordLhotka:

An object can be bound to one thing at a time. The object is bound to the datagrid, and you are then trying to bind it to the dialog, and you can't do that. You need to unbind the object from the datagrid first (which really means unbinding the entire list from the datagrid) so you can display it in the dialog...



Just out of curiosity, is this also a limitation wiht WPF?

AndyW replied on Thursday, December 03, 2009


Thanks guys for the responses.

On the face of it, all I am asking is for something that sounds really easy.

I want an editable grid and also be able to double click a row in the grid, open a new dialog, change / modify data. When I close the form save or cancel the ammended data.

The grid row should now reflect the changes I made in the popup dialog.

Sounds easy when you write it like that.

Anyhow, I am working my way through unbinding / rebinding.

I am also re-reading certain sections of the 2008 book to get a better understanding.

I does seem a little strange that I have to unbind the complete list, just to work with one object within the list. I understand that is not the frameworks fault, just a little frustrating.

At least my problem is a lot simpler than yours rsbaker0 :-)

I am going to purchase Rockys new videos, hopefully it will give me a better understanding.

RockfordLhotka replied on Thursday, December 03, 2009

WPF data binding is not as complex as Windows Forms, and so it is easier
(much easier) to do this scenario in WPF or Silverlight.

rsbaker0 replied on Thursday, December 03, 2009

We had this same issue -- even worse because we sometimes will have a grid either beside or below a non-modal form.

The only solution we found was to turn off the IEditableObject interface (DisableIEditableObject = true) in our BusinessBase derived classes.

This seems to work, but it's not free by any means. If you do this, you have to completely implement the BeginEdit/ApplyEdit/CancelEdit calls yourself, including when the current row in the grid changes from one row to another (each time you visit a row, you have to ApplyEdit on the last row visted, and BeginEdit on the new row, etc).

Copyright (c) Marimer LLC