bindingsource addingnew

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
 
R

RobinS

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,.
 
R

Rick

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
 
R

RobinS

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.
-----------------------------
 
R

Rick

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.
 
R

RobinS

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top