Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

BindingSource.ListChanged event fires 2 times when row in DataTable?

$
0
0

Hi All,

I am binding a DataTable to the DataGridView with the BindingNavigator. Here is my integration code,

BindingSource bindingSource = new BindingSource();

bindingSource.DataSource = dataTable;

this.bindingNavigator1.BindingSource = bindingSource;

this.dataGridView1.DataSource = bindingSource;

bindingSource.ListChanged += BindingSource_ListChanged;

I am processing some code in ListChanged event of BindingSource for my requirements. 

Issue is when i add row using AddNewRow button of BindingNavigator, new empty row is shown and ListChanged event of BindingSource is fired. and also when i change current record after adding new row, the ListChanged event is fired which process my requirement code once again , which i dont want to.

I found that, DataTable.Rows.Count is not updated while adding the row using BindingNavigator and only updated when we change the current record of grid. so this leads to process of my code in ListChanged event.

Could anyone please share me why DataTable.Rows.Count is not updated and ListChanged event of BindingSource is fired 2 times?

Thanks and Regards,

Amal Raj.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>