Datagrid and Child list

Datagrid and Child list

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


Antonio Sandoval posted on Tuesday, March 03, 2009

I have a class Invoice and a child List DetailInvoice. DetailInvoice is binded to a datagrid.

In the generated code I delegate the event ListChanged:
void _detailInvoice_ListChanged(....){
   OnPropertyChanged(null);
}

On this way each new row added to the List is commited inmediatly after of each ListChanged event, that causes that the user cannot press ESC to cancel the new pending row.
If I remove OnPropertyChanged it works correctly, as we can expect. I'm using Csla. 3.0.

Thanks in advance




RockfordLhotka replied on Wednesday, March 04, 2009

This sounds like a bug that was fixed in 3.0.3 or 3.0.4. Please make sure you are running the latest 3.0.x version and see if the issue has been resolved.

Antonio Sandoval replied on Thursday, March 05, 2009

Thank you for your reply rocky. I have the version 3.0.5. Yesterday I worked all the day trying to solve the problem, but I can't, here is a little example. I have ommited all my base classes and also the data access layer, maybe there is something that I'm doing wrong.

http://www.hidraquim.com/CslaDGVTest.zip

This is the version that I Have
http://lhotka.net/files/csla30/cslacs-3.0.5-081009.zip

Much appreciate the help.

Antonio Sandoval replied on Thursday, March 05, 2009

I have added a public property to BussinesBase:

public bool IsCommited {
 get{
   return !_neverCommited;
}
}

void detailInventoryList_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e){
   if(e.ListChangedType== System.ComponentModel.ListChangedType.ItemChanged &&
             detailInventoryList[e.NewIndex].IsNew && !detailInventoryList[e.NewIndex].IsCommited )
      return;
  OnPropertyChanged("detailInventoryList");
}

Maybe this is crazy, but I'm loosing the reason! :-s.
It works, but I don't know if it can be worst in other cases and I'm almost sure that this is not necessary, but I did not found another way of make it work.

Thank you for yours comments.

EDIT 1: IsCommited is always false! hehe, I change IsCommited to public, and check if the item changed is new and was never commited.
EDIT 2: Only when item change!

danielmartind replied on Friday, March 06, 2009

I have had this problem and found that adding the ListChanged event to a parent stopped the DataGridView working correctly. I have not found any solutions other than not using the event but would be interested to know if anyone comes up with anything.

Dan

Antonio Sandoval replied on Saturday, March 07, 2009

DatagridView is not working well for Lists contained inside a root, or I'm doing something wrong.
After I study the framework for a couple of days I have does not found a solution. I have added a public property to BussinesBase that returns _neverCommited, and then I check in the ListChanged event if the item has been changed, if it is new and has never commited (_neverCommited is only true when ApplyEdit has been called):

void detailInventoryList_ListChanged(object sender, ystem.ComponentModel.ListChangedEventArgs e){
   if(e.ListChangedType== System.ComponentModel.ListChangedType.ItemChanged &&
             detailInventoryList[e.NewIndex].IsNew && !detailInventoryList[e.NewIndex].IsCommited )
      return;

  OnPropertyChanged("detailInventoryList");
}

This works, the only problem that I see is that if you need to check some validation rules for the list, it will be never validated, for example, in my application I need to check if the customer has not ordered more than the authorized credit SUM(Qty*UnitCost), so this validation is checked manually at the save moment, and maybe the best way is to check on each detail change, and also I need to check that there is a least one detail in the purchase order, this is not problem because ItemAdded and ItemDeleted is catched without problems.

I was thinking that maybe the best option is upgrade to a newer version of CSLA, the new ChildChanged Event sounds good, but on my  organization there is not license for VS2008.

I need to know if there is a best way of solve this problem, please, I will be expecting for more comments. I'm sorry for my poor english language.

Thanks in advance.

Copyright (c) Marimer LLC