I cant see enough of the automatic code.. anyone know where it is?

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
With a default bindingnavigator there seems to be some code hidden somewhere behind the scenes and i want to edit or hook into it in some way..

for example when i click Add New on my binding nav (created by some wizard along with a binding source, data set and table adapter when i dropped a data source onto my form) it adds a new row to the data table.. but how? ive found AddingNew event on the binding source, which apparently lets me get access to a reference of where the new row will be when it is created... (it would have been nice if AddingNew fired after the new row had been created but before it was added)
so im going to try making a new one and populating it with some stuff

then if the user clicks one of the record movement buttons, some kind of validation is done.. but again.. WHERE? all i know is if i leave the PK field null then click nav, the app crashes with a Constraint Exception.. i want to handle it, or do some extended checks but i cant even find the code that performs the nav..

all the buttons on the default navigator.. where is the code that makes them do their magic? if you double click them you just get put to an empty click handler that doesnt override the default (hidden) code..

??

tia
 
mhhh.. it's not actually there. it seems to be some hard coded feature of a BIndingSource (which is an awkward component to work with)

if you have a Binding Nav, then it has a property "AddNewItem", and this is set to some component, or (None) - your choice. When set to a button, whenever that button is clicked, a new record is added to the DataTable via the Binding Source.. it's horrible, inflexible and the newly added row is not created until after all the relevant events have fired.. so you cant catch it in time to edit it.
You cant make your own row and add it to the binding source because it requires a datarowview object, not a datarow, and DRV has no constructors. Yopu cant make your own new row and keep the functionailty of AddNewItem because then you end up with 2 new rows - your new row and the automagic new row, so you need to disassociate the AddNewItem property from the button and then do the addition code yourself :)

What a truly horrible way of doing things - All i want to do is hook into the default Add New procedure to supply some default values (that vary according to other form contents so i cant make )

-

Writing this just gave me an idea - it works, though i'm not too impressed with it:
Just before the new row is added, in the click handler for the AddNewItem button (it is called before the new row is created) i can change the datatable's default values for a particular column.. then when my new row is created, it acquires those default values.. of course, i'll have to copy the old default values out and back again but im hoping that this can be done with a foreach loop..

i still think one thing: ugh

anyone have any better?
 
Back
Top