Update using NotifyPropertyChanged instead of Row.Invalidate

This commit is contained in:
Michael Bucari-Tovo 2021-08-20 15:38:30 -06:00
parent a8d609676e
commit d0d66c6135
3 changed files with 10 additions and 7 deletions

View File

@ -8,7 +8,7 @@ namespace LibationWinForms
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "") public void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
=> this.UIThread(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName))); => this.UIThread(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)));
} }
} }

View File

@ -60,7 +60,6 @@ namespace LibationWinForms
//DisplayTags and Liberate properties are live. //DisplayTags and Liberate properties are live.
} }
public void NotifyChanged() => NotifyPropertyChanged(nameof(GridEntry));
private void PictureStorage_PictureCached(object sender, FileManager.PictureCachedEventArgs e) private void PictureStorage_PictureCached(object sender, FileManager.PictureCachedEventArgs e)
{ {

View File

@ -101,7 +101,9 @@ namespace LibationWinForms
//Re-apply filters //Re-apply filters
Filter(); Filter();
liveGridEntry.NotifyChanged();
//Update whole GridEntry row
liveGridEntry.NotifyPropertyChanged();
} }
#endregion #endregion
@ -150,10 +152,10 @@ namespace LibationWinForms
public void RefreshRow(string productId) public void RefreshRow(string productId)
{ {
var rowIndex = getRowIndex((ge) => ge.AudibleProductId == productId); var liveGridEntry = getRowItem((ge) => ge.AudibleProductId == productId);
// update cells incl Liberate button text // update GridEntry Liberate cell
_dataGridView.InvalidateRow(rowIndex); liveGridEntry?.NotifyPropertyChanged(nameof(liveGridEntry.Liberate));
// needed in case filtering by -IsLiberated and it gets changed to Liberated. want to immediately show the change // needed in case filtering by -IsLiberated and it gets changed to Liberated. want to immediately show the change
Filter(); Filter();
@ -194,7 +196,9 @@ namespace LibationWinForms
#region DataGridView Macro #region DataGridView Macro
private int getRowIndex(Func<GridEntry, bool> func) => _dataGridView.GetRowIdOfBoundItem(func); private GridEntry getRowItem(Func<GridEntry, bool> predicate)
=> ((SortableBindingList<GridEntry>)gridEntryBindingSource.DataSource).FirstOrDefault(predicate);
private GridEntry getGridEntry(int rowIndex) => _dataGridView.GetBoundItem<GridEntry>(rowIndex); private GridEntry getGridEntry(int rowIndex) => _dataGridView.GetBoundItem<GridEntry>(rowIndex);
#endregion #endregion