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;
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
public void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
=> this.UIThread(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)));
}
}

View File

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

View File

@ -101,7 +101,9 @@ namespace LibationWinForms
//Re-apply filters
Filter();
liveGridEntry.NotifyChanged();
//Update whole GridEntry row
liveGridEntry.NotifyPropertyChanged();
}
#endregion
@ -150,10 +152,10 @@ namespace LibationWinForms
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
_dataGridView.InvalidateRow(rowIndex);
// update GridEntry Liberate cell
liveGridEntry?.NotifyPropertyChanged(nameof(liveGridEntry.Liberate));
// needed in case filtering by -IsLiberated and it gets changed to Liberated. want to immediately show the change
Filter();
@ -194,7 +196,9 @@ namespace LibationWinForms
#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);
#endregion