How to tell if user has modified data using bindingsource?

后端 未结 12 2091
南方客
南方客 2021-01-05 06:05

I have a DataGridView bound to a bindingsource which is bound to a List. The user clicks a row that goes to a form with textboxes, etc. The textboxes a

12条回答
  •  离开以前
    2021-01-05 06:26

    I made this function now. You can use like:

    if (changedOrNew(myBindingSource)){
        // Do something!
    }
    
    public bool changedOrNew(BindingSource bs){
        EntityObject obj = (EntityObject)bs.Current;
        if (obj==null)
            return false;
        return (obj.EntityState == EntityState.Detached ||
                obj.EntityState == EntityState.Added ||
                obj.EntityState == EntityState.Modified);
    }
    

提交回复
热议问题