HI!
I have a DataGridView, bound to a SortableBindingList on my presentation model. I also have several other controls bound to properties of the same model. They're all updated OnPropertyChanged. My problem is, for every property that is being updated, after selecting a row on the DGV, the SelectionChangedEvent is being fired twice. Because of this, when I select a row, the SelectionChanged event is fired like 13 times. I don't see how the properties bound to other controls are connected to the DGV, other than them sharing a bindingSource. Could someone explain this to me and maybe give some suggestions on how to avoid this sort of behaviour? Is there a better event to catch than SelectionChanged? I'm very close to going back to manual synchronization.
VIEW
privatevoid shopSalesDGV_SelectionChanged(object sender,EventArgs e){if(shopSalesPresentationModel ==null)return;if(shopSalesDGV.SelectedRows.Count==1){Console.WriteLine("SelectionChanged called: "+++eventCalledCount +" times. Selected index = "+ shopSalesDGV.SelectedRows[0].Index);
shopSalesPresentationModel.SelectedShopSaleIndex= shopSalesDGV.SelectedRows[0].Index;}}
PRESENTATION MODEL
publicintSelectedShopSaleIndex{
get {returnthis.selectedShopSaleIndex;}set{if(this.selectedShopSaleIndex != value){this.selectedShopSaleIndex = value;Console.WriteLine("SelectedShopSaleIndex set.");OnShopSaleSelected();}}}privatevoidOnShopSaleSelected(){CurrentShopSale= shopSales[selectedShopSaleIndex];this.ShopSaleId=CurrentShopSale.Id.ToString();this.Date=CurrentShopSale.SaleDate;this.Note=CurrentShopSale.Note;this.GrossSum=CurrentShopSale.GrossSum.ToString("C2");this.Items=newSortableBindingList<ItemViewObject>(CurrentShopSale.Items);}publicstringShopSaleId{
get {returnthis.id;}set{
id = value;Console.WriteLine("ShopSaleId set.");OnPropertyChanged("ShopSaleId");}}...