Skip to content

Commit

Permalink
Fix flickering in ListView using double buffering. Also use BeginUpda…
Browse files Browse the repository at this point in the history
…te and EndUpdate (didn't fix it alone, but is recommended and seemed to be a slight improvement).
  • Loading branch information
Poikilos committed Dec 20, 2023
1 parent f437dcc commit 69504c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DFF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ private static void AddListViewItem(ListView box, ListViewItem item) {
if (box.InvokeRequired)
{
// System.Windows.Forms.MethodInvoker
box.Invoke((MethodInvoker)(() => box.BeginUpdate()));
box.Invoke((MethodInvoker)(() => box.Items.Add(item)));
box.Invoke((MethodInvoker)(() => box.EndUpdate()));
}
else
{
box.BeginUpdate();
box.Items.Add(item);
box.EndUpdate();
}
}
public void AddItem(ListViewItem item) {
Expand Down
15 changes: 15 additions & 0 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,22 @@ public MainForm()
this.lvwColumnSorter = new ListViewColumnSorter();
this.resultsListView.ListViewItemSorter = this.lvwColumnSorter;
// ^ It still flickers without this.
SetDoubleBuffered(this.resultsListView, true);
}

/// <summary>
/// Sets the double buffered property of a list view to the specified value
/// (Based on <https://stackoverflow.com/a/42389596/4541104>).
/// </summary>
/// <param name="listView">The List view</param>
/// <param name="doubleBuffered">Double Buffered or not</param>
public static void SetDoubleBuffered(System.Windows.Forms.ListView listView, bool doubleBuffered)
{
listView
.GetType()
.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(listView, doubleBuffered, null);
}

public void setSearchAvailability(bool enable) {
findButton.Enabled=enable;
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [3.2.1] - 2023-12-20
### Fixed
- Fix flickering in ListView finally (Use double buffering).


## [3.2.0] - 2023-09-20
### Added
- Select multiple entries (issue #14). Required by:
Expand Down

0 comments on commit 69504c2

Please sign in to comment.