Here I will post problems I and my colleagues met and solutions we found.

Tuesday, February 22, 2005

Master/detail part II

When first problem was resolved I had another one. This one took much time for me to figure out workaround, although, I had to find it faster.

Anyway. The problem was that after inserting from previous topic was done and all data were posted to the server, grid with addresses became empty. I checked data in DataView, in DataTable - data were correct. Later I found that if position was changed in master, details were updated.

I tried to call BindingContext[dataSource, dataMember].Refresh(), where dataMember was the name of my relation, it did not help. So, I did not find anything better but to write something like this

m = BindingContext[dataSource];
int p = m.Position;
m.Position = 0;
m.Position = p;

BTW, for some reasons this code made my data in Edit mode again, so I added
m.CancelCurrentEdit(), because I was sure I did not edit anything.

But later I found very good article that described this problem and recommended replace it the
m.Refresh().
m.CancelCurrentEdit(). // still need this one.

Now this looks obvious for me and I don't know how could I not to try it myself. Anyway, it looks like bug in .NET, I would prefer not to do anything.

Here is the article I was talking about, recommend it very much:
http://msdn.microsoft.com/library/en-us/dnwinforms/html/databinding_winforms10_11.asp?frame=true&_r=1

This problem is discussed in Chapter When to Call CurrencyManager.Refresh, but I recommend to read whole article.

No comments: