Debugging Help: 2 lists, one works fine adding object, other loses first keystroke?

Debugging Help: 2 lists, one works fine adding object, other loses first keystroke?

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


rsbaker0 posted on Saturday, October 18, 2008

This a weird WinForms problem using a DevExpress grid and I was just hoping someone could point me in the right direction.

When I start typing in the "new item row" in one list, it works perfectly. The child object gets created and initialized and the first keystroke shows up in the field.

In the problem list, a child object is created, but the property setter for the property mapped to the column I'm editing doesn't get called, and the first keystroke doesn't show up. However, it works fine after that. It doesn't matter which column I type in or what data type it is (or even if I'm using a DevExpress editor control like a drop-down to supply the value) -- the  very first property change is lost.

Any thoughts on how I might troubleshoot this? The ironic thing is that both the lists are the same class type. It's a generic "MyBusinessListBase<T>" class where the only thing different is T, so I'd think it would have to be related to something specific about the class supplied for T.

It's probably raising some event (or not raising the right event) during creation of the child object in AddNewCore, but I'm not sure where to start.  

stefan replied on Sunday, October 19, 2008

Just thinking:

Look at any method overrrides in your problematic class.
Maybe you forgot to call the method implementation in the base class
(MyBase.MethodName) or you encounter an exception,
thus breaking the flow of events...?

Stefan

rsbaker0 replied on Monday, October 20, 2008

Sigh. It turns out I'm just meddling with things without completely understanding the implications. This a seemingly constant peril for a recovering C++ programmer who only moved to  C# and .NET a year ago. :)

It turns out the problem wasn't with C (sorry, I had this confused earlier), but with my override of AddNewCore() in MyBusinessListBase<T, C>.

I tracked this down by testing MyEditableRootListBase<T, C> with the same class C, and it worked fine. So, I just analyzed what was different between them.

Doesn't work:

protected override void OnAddingNew(AddingNewEventArgs e)
{
   C newObject = CreateChild();
   e.NewObject = newObject;
}
protected override object AddNewCore()
{
   object result = base.AddNewCore();

   // Propagate parent primary key to foreign key references when new
   // child object added to exsting object

   SetChildForeignKey(result);
   return result;

}

Works:

protected override object AddNewCore()
{
   C result;

   result = CreateChild();
   OnAddingNew(new AddingNewEventArgs(result));

   // Propagate parent primary key to foreign key references when new
   // child object added to exsting object

   SetChildForeignKey(result);
   Add(result);
   return result;
}

 

Maybe someone can enlighten me, but I have to just chalk this up to voodoo for the moment... :(

 

rsbaker0 replied on Monday, October 20, 2008

OK, some of the voodoo is starting to clear.

In trying to clean this up, I prompt broke it again without realizing it. I had tried to move some code to an override of InsertItem, calling BusinessListBase.InsertItem() first, and

It looks it's probably related to something that fires a property change after the list events have been hooked in InsertItem (e.g. during the processing of AddNewCore()) causes the behavior I observed.

FatPigeon replied on Monday, October 20, 2008

I seem to remember getting something like this during the development of a form using the DataGridView. Unfortunately I cannot remember what I did about it. I have had a look at the code in that form and there is nothing obvious. All I can suggest is that is something to do with the code already in your form. How about chopping out code in your form bit by bit on a trial basis until the issue goes away. Clearly this is not a solution, but it may help identify the code that is causing the problem.
 
Regards,
 
Patrick
 
 
 
 
 
----- Original Message -----
From: rsbaker0
To: patrick@ashmeadapplications.co.uk
Sent: Saturday, October 18, 2008 1:54 PM
Subject: [CSLA .NET] Debugging Help: 2 lists, one works fine adding object, other loses first keystroke?

This a weird WinForms problem using a DevExpress grid and I was just hoping someone could point me in the right direction.

When I start typing in the "new item row" in one list, it works perfectly. The child object gets created and initialized and the first keystroke shows up in the field.

In the problem list, a child object is created, but the property setter for the property mapped to the column I'm editing doesn't get called, and the first keystroke doesn't show up. However, it works fine after that. It doesn't matter which column I type in or what data type it is (or even if I'm using a DevExpress editor control like a drop-down to supply the value) -- the  very first property change is lost.

Any thoughts on how I might troubleshoot this? The ironic thing is that both the lists are the same class type. It's a generic "MyBusinessListBase<T>" class where the only thing different is T, so I'd think it would have to be related to something specific about the class supplied for T.

It's probably raising some event (or not raising the right event) during creation of the child object in AddNewCore, but I'm not sure where to start.  




Copyright (c) Marimer LLC