Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.5 C# LINQ SQL WinForm
I have a Windows Forms app with databinding (yes, I know, shoot me now) and it has a "Save" toolbar button. I want to gray out the "Save" button unless the user has made a change to the form control that will change a property on the DataContext.
 
The table has 100's of properties so I don't want to implement
 
partial void OnXXXChanged(XXX value)
{
 
}
 
over and over again. My thought was to add a delegate to the DataContext partial class and maybe a polling thread to check the properties and ask if they've been changed.
 
DataContext appears to implement INotifyPropertyChanged etc but I can't seem to tie onto the PropertyChanged event from my Model.
 
How can I detect, essentially, the condition "hey! you need to call SubmitChanges() stoop!" and get a notification when that happens so I can un-gray the save button?
Posted 22-Jun-12 10:23am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

*Nevermind*
 
One way, a total hack is to do
 
partial class DbDataContext
{
    public bool IsDirty { get; set; }
 
    partial void OnCreated()
    {
        Application.Idle += (sender, e) =>
        {
            ChangeSet set = GetChangeSet();
 
            IsDirty = set.Inserts.Count > 0 || set.Updates.Count > 0 
                 || set.Deletes.Count > 0;
        };
    }
}
 
And of course also update the Save button on Application.Idle.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 22 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100