Alternative to DataGridView DataBindingComplete Event

后端 未结 2 1488
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 23:56

As stated here the DataBindingComplete event for a DataGridView is fired whenever the contents of the data source change, or a property such as DataSource

2条回答
  •  不要未来只要你来
    2021-01-25 00:23

    Yes, you can use DataSourceChanged event, but be aware, that it occurs only when data source is changed. Additionally, DataBindingComplete offers you information why it has happend - through e.ListChangedType:

    Reset = 0,//     Much of the list has changed. Any listening controls should refresh all their data from the list.
    ItemAdded = 1,//     An item added to the list
    ItemDeleted = 2,//     An item deleted from the list.
    ItemMoved = 3,//     An item moved within the list.
    ItemChanged = 4,//     An item changed in the list.
    PropertyDescriptorAdded = 5,//     A System.ComponentModel.PropertyDescriptor was added, which changed the schema.
    PropertyDescriptorDeleted = 6,//     A System.ComponentModel.PropertyDescriptor was deleted, which changed the schema.
    PropertyDescriptorChanged = 7//     A System.ComponentModel.PropertyDescriptor was changed, which changed the schema.
    

    According to this answer: https://social.msdn.microsoft.com/forums/windows/en-us/50c4f46d-c3b8-4da7-b08f-a751dca12afd/databindingcomplete-event-is-been-called-twice the whole thing happens because you don't have DataMember property set in your dataGridView. And you can set it only if you want to set particular table from database which is set as your DataSource of dataGridView. Other way - throws an exception.

提交回复
热议问题