bindingsource addingnew

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

I have a bindingsource filled by a strongly-typed table via a tableadapter.

I have connected the binding source to the AddingNew event where I want to
supply some values for the new row.

The problem is that this event is triggered when the TableAdapter fills the
binding source.

I'm not sure why this event is triggered by the fill, but is there some way
to either stop this or figure out if the event was called by an actual new
row, or by an adapter fill?

Rick
 
If you are trying to handle the event, try setting a variable like _Loading
to True before calling the Fill on the table adapter and checking for it in
your event procedure (if !_Loading {do my code}). Then after the fill, set
it back to false so your event code will be used.

I've heard you can unhook the event and then hook it back up, but I'm too
lazy to do that. ;-)

Robin S,.
 
Thanks Robin,

I figured as much, but it seems odd that one: the event is triggered at all
from a Fill and two: there is no property to distinguish if this is the
case.

Perhaps someone from MS can explain if this is "by design" for some reason?

Rick
 
I'm sure it's by design. I also think it's triggered each time a record is
added to the data source, and that's what Fill does. For all .Net knows,
you actually want to catch each of the adds when it fills the data, and do
something. So try to think of it as being flexible and giving you more
options rather than being a pain in the a**. ;-)

Robin S.
-----------------------------
 
I'll try to think of that extra flexibility next time I spend a few hours
wondering if I've done something wrong or it just doesn't work as expected.
:-)

Anyway, I used your flag idea in another way today. I have a "host" form
with several optionally created forms parented in tab controls. Oddly, the
OnClosing event does not happen in the "child" forms when the parent closes.
So I explicitly check if the child form isnot nothing and then close it.
This causes the child OnClosing event to trigger as expected. Then from the
child form I set a flag in the parent so I can set the e.Cancel based on the
child form results.

Thx.
 
Rick said:
I'll try to think of that extra flexibility next time I spend a few hours
wondering if I've done something wrong or it just doesn't work as
expected. :-)

Join the crowd!

Anyway, I used your flag idea in another way today. I have a "host" form
with several optionally created forms parented in tab controls. Oddly,
the OnClosing event does not happen in the "child" forms when the parent
closes. So I explicitly check if the child form isnot nothing and then
close it. This causes the child OnClosing event to trigger as expected.
Then from the child form I set a flag in the parent so I can set the
e.Cancel based on the child form results.

You should never underestimate the power of the silly-seeming but simple
solution. :-)

Robin S.
 
Back
Top