How to tell if user has modified data using bindingsource?

后端 未结 12 2099
南方客
南方客 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:44

    A simpler approach would be to subscribe to the BindingSource's ListChanged event and set an IsDirty flag based on the event type.

    categoryBindingSource.ListChanged += 
    new System.ComponentModel.ListChangedEventHandler(categoryBindingSource_ListChanged);
    

    and set IsDirty = true in the event method...

    void customerAccountBindingSource_ListChanged(object sender, system.ComponentModel.ListChangedEventArgs e)
    {
        if (e.ListChangedType == System.ComponentModel.ListChangedType.ItemChanged)
            _isDirty = true;
    }
    

    A word of caution here, it would not be able to detect when the modified value is still same as the original value. Memberwise.Clone can be used additionally if that level of accuracy is required.

提交回复
热议问题