StrataFrame Forum

DevExpress grid, new row, misses first letter on edit

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

By George Nentidis - 1/14/2008

Hi

This is another thing I came on today.

I use DevExpres grid and BusinessBindingSource to edit a BO. DevExpress grid has an empty row, that is used for inserting new rows in the grid. When trying to insert a new row, I click on the grid's empty row and type something in. The first character I type is always lost. Then the cell leaves edit mode, and then I type again and everything works fine. But the first character is always lost. For instance if I try to type "George" the actuall thing that the cell will contain is "eorge". And this only happens when I set default values on the BO_SetDefaultValues event handler. If the handler is empty, all work fine.

My SetDefaultValues handler is:

private void ContactBO_SetDefaultValues()
{
  
this.ContactID = Guid.NewGuid();
  this.ContactType = 3;
}

But, when I make a BeginEdit in the current row:

private void ContactBO_SetDefaultValues()
{
  this.CurrentRow.BeginEdit();
  this.ContactID = Guid.NewGuid();
  this.ContactType = 3;
}

then all work fine when inserting new row in a grid which has some rows already. When I try to insert a new row in a grid with no rows at all, the same thing still happens. The first character I type is lost.

I have tried to set default values, on the OnAfterAddNew, OnBeforeAddNew, OnEditingStateChanged events, nut still the same thing happens.

Has anyone seen that before?

By Trent L. Taylor - 1/14/2008

Yes.  This is generally due to how the binding is being updated.  This is most common when the binding property is set to update the source on the Validated versus the PropertyChanged event.  You might check your bindings and set this to update your bound property on the PropertyChanged event to see if you have a different result.

One other thing to look at may be the BusinessBindingSource sample that comes with the framework.  You might "compare notes" to see if there is something missing.  Finally, you might see if you have the same problem with a DataGridView instead of the DevExpress grid so that you know you are having the same behavior accross the board and this is not related specifically to the DevExpress grid.

By Chan - 1/14/2008

Hi,

I was facing the same problem. After long time investigation from DevExpress and SF team, I give up to use new row in XtraGrid with SF BBS.



I have posted this to SF team but haven't get any reply.



However, according to DevExpress team (I sent them sample project, and they tried using SF trial version) the way of SF BBS binding is a bit weird for them which is not compatible with xtragrid. They provided some workaround but cause another problem. At last, they recommend me to not use new row.
By George Nentidis - 1/14/2008

Thank you Chan.

Do you remember what the workaround was?

By George Nentidis - 1/15/2008

Trend,

The PropertyChanged, etc. options are in the DataBinding collection of controls. The grid does not work with DataBindings collection, so I can't use it.

Also the BusinessBindingSource does nothing different than my code. The DataGridView works fine. The problem only happens with DevExpress grid. But then again if DataGridView was enough nobody whould need DevExpress...

Have you tried a BusinessBindingSource sample using DevExpress grid?

By Chan - 1/15/2008

Hi,

Hope this help



http://www.devexpress.com/Support/Center/p/CQ57816.aspx



Unbound column and new item row
By Trent L. Taylor - 1/15/2008

But then again if DataGridView was enough nobody whould need DevExpress...

I was not suggesting that you use this control...I was trying to identify where your problem was.  Also, this control does far more than you may give it credit for.  Infragistics UltraGrid actually inherits off of this control and then implements all of their logic...so if you have the time and patience, you can do a lot with the DataGridView.

Have you tried a BusinessBindingSource sample using DevExpress grid?

Yes, and it works without issue.  I suggest that you create a small sample that reproduces your problem and post it here on the forum so I can take a look.

By George Nentidis - 1/15/2008

Trent

I had no intention of affending anyone. But I want you to be sure that before I post anything in the forum, I try a lot to make it work. I know that your time (as everyone's) is valuable.

The minute I have some time I will send you a sample.

By Trent L. Taylor - 1/16/2008

George, if I offended you that was not my intention.  I can tell through our interation thus far that you are a solid developer and I know that you attempted to work the problem.  The reason I suggested a quick sample is because this is a control that a lot of our developers use out there and I would be curious to see why it might be failing.  Hope this helps your understand where I was coming from Smile
By George Nentidis - 1/18/2008

Trent,

Here's the sample I promised you.

I have taken the BusinessBindingSource sample and added a DevExpress grid on the form. The only thing I changed on the grid is the NewItemRowPosition.

Now try to add a new row by typing directly to grid's NewRow added at the bottom of the grid. You will see that the first character you type will be lost. This happen when I set default values in CustomersBO in the CustomersBO_SetDefaultValues event. Remove or comment the line

this.cust_Email = "someone@somewhere.com";

and all will work fine.

Also placing the CurrentRow.BeginEdit just before the assigment seem to fix the problem, but not when you add the first row in an empty BO.

this.CurrentRow.BeginEdit();
this.cust_Email = "
someone@somewhere.com";

I hope all these can help you fix it quickly (next build for instance BigGrin).

Thank you

By Trent L. Taylor - 1/18/2008

OK...this ended up being an issue with how the DevExpress XtraGrid refreshes itself.  I know that we have a large number of users using an XtraGrid and I would have to go back to previous versions to see if this issue manifested itself in those versions, but here is the problem and how to fix it.

DevExpress is handling the Changed event of each individual strong-typed property, so when the Changed event is raised it is refreshing the grid...but it is NOT updating the property value before it refreshes...so it is a "catch 22" type of situation.  To work around this, we have added two methods PauseChangedEvents and ResumeChangedEvents on the Business Objects (BusinessLayer class).  In the top of the SetDefaultValues method, call this.PauseChangedEvents and once the properties have been set, call this.ResumeChangedEvents.  This will prevent the grid from stripping the text.

Copy the attached assembly into your GAC (c:\windows\assembly) and copy both the DLL and XML to the c:\program files\Common Files\MicroFour\StrataFrame folder.

This should get you going Smile

Obviously this will be included in the next update Wink