I already have a solution for doing the sync part.
The question I really need answered is the original one that I posted here:
When I have used all of the built in drag and drop tools to build and
application how do I get notified when an SQL statement gets called so that I
can do something at that point?
To recap:
I created a form. I put a DataGridView on it. I dragged a data source onto
the DataGridView. I told it to generate all the templates.
Now when I use the auto generated UI to create a new record or edit a record
or delete a record I can't seem to find anywhere to get notified of this. I
put break points inside the data source and other places and nothing ever
gets called. Everything just happens auto-magically. That is good because I
wanted it to be auto-magic so I didn't have to write a bunch of code. It is
bad because I can't find a place to insert my own logic.
So, is there a way to insert my own logic in this case?
There probably is a way to insert your own change tracking logic, but I
think using Sync Services, which already provides change tracking logic
inside the SQL Compact engine might be easier in the long run. There is a
CTP you can download that handles syncing with a mobile device, but again
the desktop piece is SQL Server so you'd still need to write a custom sync
adapter to use SQL Compact as the desktop server. Here's the link if the CTP
interests you:
http://www.microsoft.com/Downloads/details.aspx?familyid=75FEF59F-1B5E-49BC-A21A
-9EF4F34DE6FC&displaylang=en
Since you're talking about DataGridView, I assume you want to track the
changes on the desktop, but the desktop app doesn't have access to the data
on the device. Are you perhaps considering getting the changed data onto the
device in some other fashion? But in any case, the usual sequence of events
for data bound controls like DataGridView is that moving to a new row in the
grid calls EndEdit which in turn calls Update on the bound data adapter.
Brian Noyes wrote a very good book called Data Binding with Windows Forms
2.0 that covers this sort of stuff in detail, some of which I've
unfortunately forgotten, but the main thing I do remember is tha tthe
BindingSource control is the bit that provides the glue between the GUI
control and the underlying data, so look at the event handlers for
BindingSource such as AddingNew, BindingComplete, CurrentChanged,
CurrentItemChanged, PositionChanged, etc., to see which does what you want.
HTH,
Ginny
>I already have a solution for doing the sync part.
>
[quoted text clipped - 157 lines]
>> >> >
>> >> > Ideas?

Signature
Ginny Caughey
Device Application Development MVP
www.wasteworks.com
Software for Waste Management
apitman - 24 Apr 2008 19:27 GMT
Thank you for the comments. To answer your question I have to say that as
soon as syncing supports SQLCE without having to have SQL Server and IIS I
will use it.
I have both desktop and PDA applications. They will sync their data
together. It is such a simple application that I don't want to have to
install SQL Server and IIS just to sync.
The method I have taken is that I will use RAPI to copy the mobile database
to the desktop and then I will simply use SQLCE on the desktop and sync them
together. Again there is nothing built in to Sync that provides syncing 2
SQLCE database. They still require SQLS and IIS to do it (see comment above).
I found the events you are talking about. I think this might be what I was
looking for. Already I ran into a problem, however, in the AddingNew event
the e.NewObject is null.
I also handle CurrentChanged and CurrentItemChanged. I look at
bindingSource.Current and can see the row data. I also tried looking at
bindingSource.Current in AddingNew and it does show the item values. This is
good. I should be able to use this.
The one down side I found is that even though there are a couple of
parameters in bindingSource.Current for IsNew and IsEdit they are always
false even if I am adding or changing the value. Any ideas on that?
The bottom line is that this answer my main question. Thanks a bunch! If you
can answer why the IsEdit and IsNew are not set that would help too. For now
I will just have to detect whether something has changed or now. I will also
use the fact that AddingNew is the event to detect a new record.
> There probably is a way to insert your own change tracking logic, but I
> think using Sync Services, which already provides change tracking logic
[quoted text clipped - 183 lines]
> >> >> >
> >> >> > Ideas?
Ginny Caughey MVP - 24 Apr 2008 19:41 GMT
I understand very well why you use Rapi instead of a syncing solution
involving IIS. I do the same!
If you have more questions about data binding, you might want to ask on the
WindowsForms newsgroup. They may not be as familiar with SQL Compact as we
are here, but just don't tell them that's what you're using <g> and they can
probably answer your specific binding questions better than I can at this
point. My GUESS about IsEdit and IsNew is that the underlying objects don't
set those to true for some reason, but that's only a guess and not very
helpful.
Ginny
> Thank you for the comments. To answer your question I have to say that as
> soon as syncing supports SQLCE without having to have SQL Server and IIS I
[quoted text clipped - 251 lines]
>> >> >> >
>> >> >> > Ideas?

Signature
Ginny Caughey
Device Application Development MVP
www.wasteworks.com
Software for Waste Management
apitman - 24 Apr 2008 19:40 GMT
Correction. The IsNew and IsEdit is being set in the CurrentChanged and
CurrentItemChanged, but in ways I don't understand. The IsEdit is always set
when moving from one record to the next even if nothing changed.
I think I am getting the hang of this. There are other parameters in the
classes that indicate things.
I just realized another question however....none of these changes actually
gets put into the database until you hit the save button on the navigation
bar (again using the auto generated stuff). So the user might change stuff
and then change it back and this might mean that I don't want to update my
meta data at the binding source point.
Is there a way to get at the actual point where SQL statements are being
executed on the underlying database?
> There probably is a way to insert your own change tracking logic, but I
> think using Sync Services, which already provides change tracking logic
[quoted text clipped - 183 lines]
> >> >> >
> >> >> > Ideas?
Ginny Caughey MVP - 24 Apr 2008 19:47 GMT
EndEdit is the point at which the grid desides it's time to really update
the changes, and I imagine that gets called by the Save button. The logic in
the Save button event handler could look at the data adapter and call
GetChanges to see what is different, and you could iterate through the
changes, but there might be an easier way to go about it. I think the next
step might be to step into everything that happens from the time the Save
button is clicked and see where you might want to override something with
your own logic.
Ginny
> Correction. The IsNew and IsEdit is being set in the CurrentChanged and
> CurrentItemChanged, but in ways I don't understand. The IsEdit is always
[quoted text clipped - 230 lines]
>> >> >> >
>> >> >> > Ideas?

Signature
Ginny Caughey
Device Application Development MVP
www.wasteworks.com
Software for Waste Management
apitman - 24 Apr 2008 19:57 GMT
Thanks again. I will try that. I will also try posting in the other forum as
well.
> EndEdit is the point at which the grid desides it's time to really update
> the changes, and I imagine that gets called by the Save button. The logic in
[quoted text clipped - 241 lines]
> >> >> >> >
> >> >> >> > Ideas?