Edit,bindinsource,...?

Edit,bindinsource,...?

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


shahram posted on Wednesday, July 12, 2006

Hi!

I have a combobox on a form that shows a person info and combobox shows person's type so it is databind to typeid of person by selectedvalue. Now when I shows the form combobox seems writes to person object's typeid not read fron it! So I must click a cancel buttin that do bindinsource.CancelEdit() then combobox shows the type like after a canceledit() combobox reads tyoeid from person object to it's selectedvalue!

I wonder if it is better and faster to avoid databinding and do it by hand!

Any idea how to solve this problem?

Then I have solved all this "editlevel bigin edit canceledit applyedit one time by bindingsource, one time by csla object! "  I think but I am not sure so any suggestion?

My solution

While(object.MyEditLevel>0)--MyEditLevel is a public getter that return EditLevel

object.CancelEdit()

before every bindingsource.Datasource = object;

and

 

While(object.MyEditLevel>0)--MyEditLevel is a public getter that return EditLevel

object.ApplyEditEdit()

before every  object.Save()

Regards

RockfordLhotka replied on Wednesday, July 12, 2006

If tis is in .NET 2.0, there was a previous thread on this subject. It turns out that you should avoid calling BeginEdit/CancelEdit/ApplyEdit directly when using Windows Forms data binding.

Instead, you need to always interact with the bindingsource control - calling its EndEdit and CancelEdit methods instead, and allowing it to call BeginEdit automatically by itself.

shahram replied on Wednesday, July 12, 2006

Yes, I have read that but the issue is in my case I have a roo object(Client) with child collection(Contacts) when I show a Client in win form using bindinsource it gets one beginedit by bindingsource so now editlevel is 1 and then if user clicks a contact so anouther winform opens showing the contact and bindingsource on contact winform does a beginedit on contact now editlevel is 2!

and when after you edit your contact and want to update you do endedit and root.save but now editlevel is 1and BUMP exception!

So I thout before calling save do a

While(EditLevel>0)

object.ApplyEdit().

and it seems it works!

Anyhow it wasn't better if when you do a beginedit on a rootobject it automatically wouldn't increase editlevel on children of thet object?

Regards

 

Copyright (c) Marimer LLC