Databinding snafu

time to read 2 min | 239 words

A few hours ago I thought that I was going crazy, I'd had a form that wouldn't save changes unless I closed it without saving first. I debugged it long and hard, and I couldn't find any reason whatsoever for this. Saving and then closing wouldn't work, but closing and saying yes to the unsaved message would.

The call stack from each was the same, and for the life of me I couldn't find what is wrong. I was ready to get NHibernate's code and start debugging that (I'm pleased to say that so far I didn't get to find any bugs in it :-) ). However, I turned on logging first and realized that NHibernate wasn't issuing an update statement at all. The only case where NHibernate doesn't execute an update statement when you tell it to is when you don't have any updates to your object.

That was the answer, I was using databinding in the form, and the field I was changing wouldn't update the datasource until it lost focus (which is reasonable, I guess), but it cause me no end of grief. When I moved the focus to another control, it worked.

Just goes to say that you really needs to know what you are doing before you do it*.

*This is my first serious attempt of using databinding.