diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj index 4a8a083d..a0c9d5bc 100644 --- a/AppScaffolding/AppScaffolding.csproj +++ b/AppScaffolding/AppScaffolding.csproj @@ -3,7 +3,7 @@ net5.0 - 6.0.4.1 + 6.0.5.1 diff --git a/LibationWinForms/Dialogs/RemoveBooksDialog.Designer.cs b/LibationWinForms/Dialogs/RemoveBooksDialog.Designer.cs index 93074a78..ea2551ce 100644 --- a/LibationWinForms/Dialogs/RemoveBooksDialog.Designer.cs +++ b/LibationWinForms/Dialogs/RemoveBooksDialog.Designer.cs @@ -38,7 +38,7 @@ namespace LibationWinForms.Dialogs this.authorsDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.miscDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.purchaseDateGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.gridEntryBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.gridEntryBindingSource = new LibationWinForms.SyncBindingSource(this.components); this.btnRemoveBooks = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this._dataGridView)).BeginInit(); @@ -176,7 +176,7 @@ namespace LibationWinForms.Dialogs #endregion private System.Windows.Forms.DataGridView _dataGridView; - private System.Windows.Forms.BindingSource gridEntryBindingSource; + private LibationWinForms.SyncBindingSource gridEntryBindingSource; private System.Windows.Forms.Button btnRemoveBooks; private System.Windows.Forms.Label label1; private System.Windows.Forms.DataGridViewCheckBoxColumn removeDataGridViewCheckBoxColumn; diff --git a/LibationWinForms/ProductsGrid.Designer.cs b/LibationWinForms/ProductsGrid.Designer.cs index 335469f3..689bd848 100644 --- a/LibationWinForms/ProductsGrid.Designer.cs +++ b/LibationWinForms/ProductsGrid.Designer.cs @@ -30,7 +30,7 @@ { this.components = new System.ComponentModel.Container(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - this.gridEntryBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.gridEntryBindingSource = new LibationWinForms.SyncBindingSource(this.components); this.gridEntryDataGridView = new System.Windows.Forms.DataGridView(); this.dataGridViewImageButtonBoxColumn1 = new LibationWinForms.LiberateDataGridViewImageButtonColumn(); this.dataGridViewImageColumn1 = new System.Windows.Forms.DataGridViewImageColumn(); @@ -222,7 +222,7 @@ #endregion - private System.Windows.Forms.BindingSource gridEntryBindingSource; + private LibationWinForms.SyncBindingSource gridEntryBindingSource; private System.Windows.Forms.DataGridView gridEntryDataGridView; private LiberateDataGridViewImageButtonColumn dataGridViewImageButtonBoxColumn1; private System.Windows.Forms.DataGridViewImageColumn dataGridViewImageColumn1; diff --git a/LibationWinForms/SyncBindingSource.cs b/LibationWinForms/SyncBindingSource.cs new file mode 100644 index 00000000..67091443 --- /dev/null +++ b/LibationWinForms/SyncBindingSource.cs @@ -0,0 +1,28 @@ +using System; +using System.ComponentModel; +using System.Threading; +using System.Windows.Forms; + +// https://stackoverflow.com/a/32886415 +namespace LibationWinForms +{ + public class SyncBindingSource : BindingSource + { + private SynchronizationContext syncContext { get; } + + public SyncBindingSource() : base() + => syncContext = SynchronizationContext.Current; + public SyncBindingSource(IContainer container) : base(container) + => syncContext = SynchronizationContext.Current; + public SyncBindingSource(object dataSource, string dataMember) : base(dataSource, dataMember) + => syncContext = SynchronizationContext.Current; + + protected override void OnListChanged(ListChangedEventArgs e) + { + if (syncContext != null) + syncContext.Send(_ => base.OnListChanged(e), null); + else + base.OnListChanged(e); + } + } +}