none
Context.ObjectStatemanager to mark a proprety as edited in winforms, No ButtonClick RRS feed

  • Question

  •     This is how my project structure looks like
        

        
          namespace Factory.Model
        {
        
            Public Partial class FactoryEntities:Dbcontext{
            
            public FactoryEntities() 
               :base("name="factoryentities")
            {
               this.configuration.lazyloading = false;
            }
            
              public DbSet<Factory> Factories{ get; set; }
               public DbSet<FactoryCoverage> FactoryCoverages { get; set; }
            
            }
        
        }

    This is the Business logic
    Here's how I use the Entities

        namespace Factory.Business
        {
           partial class Class1
        {
            Factory.Model _factory;
            private LoadMethod(long id)
        {
        using(var fnt = new FactoryEntities())
        {
        
         _factory = fnt.factories.include(.)....
        }
        }
       

    Once all the items and entities are loading into the _factory object, some Winforms are called 

        Form1 f1=new Form1(_factory)
        BindingSourcef1.DataSource = _factory
        Form f1 has some textboxes bound to the BindingSourcef1
        this.textbox1.databindings.add("EditValue",this.BindingSourcef1, "Address.City", true));

    Question: How do I track changes to this textboxes. Something like, when a user changes a textbox value, notify the user with an asterisk(*) that there are changes made to the form?
    I was able to make this work by handling textbox edit value event.
    Is there an alternative to this?Handling it at Bindingsource level would be ideal.

    I want to track the change immediately to notify the user that there is an edit .No button click is involved yet. I could easily track it on SaveChanges.  context.Savechanges(); or context.ObjectStateManager. Also, Currentitemchanged dosen't seem to be executed. So the property should be marked as edited. 

    sunDisplay

    Sunday, October 27, 2013 4:53 AM

Answers