DataBindingComplete is getting called multiple times

前端 未结 2 973
南方客
南方客 2020-12-21 00:39

I am creating a windows application in c#,

I have 1 Datagridview and after I set it\'s DataSource it should have 3 Rows.

I have attached 2 Event Habdlers to

相关标签:
2条回答
  • 2020-12-21 01:04

    From msdn online DataBindingComplete Event

    This event is raised when the contents of the data source change or when the value of the DataSource, DataMember, or BindingContext property changes.

    E.g. If you are assigning Datasource, and then adding 3 rows --> 4 times event fired

    0 讨论(0)
  • 2020-12-21 01:10

    I believe it depends on your other methods, where you're actually setting the DataSource. It seems to me like you're either setting the DataSource twice or calling DataBind twice, and on each DataBind you're actually getting two rows into the DataGridView, thus the 4 total.

    Some additional code might help...

    Some things to try: search for DataBind(), DataSource(), etc in your code and make sure it's only being called in the appropriate places.

    Additionally, it's not necessarily bad for the DataBind to be called twice, assuming something changes between the databinds... some change of state... really hard to say without background.

    0 讨论(0)
提交回复
热议问题