Search and sort large Windows Forms flow layout panel

I have a program which is very simple and has a list of controls in a flow layout panel. Each one must be loaded, and I am doing that asynchronously then adding them with Invoke. There are several hundred controls each one containing 10 images, and each one must be loaded from the hard drive, so it gets very slow. This panel should also be searchable, such that only items that match a query string show up. I was writing an Identical project in Java and accomplished this like so:

list.sort(); String filter = searchBox.getText(); listPanel.removeAll(); for(MyPanel panel:list){ if(panel.matches(filter)){ listPanel.add(panel); } } listPanel.revalidate(); listPanel.repaint(); 

This runs basically instantly with very little CPU usage, and I cannot find a way to accomplish the same thing using Windows Forms that is nearly as quick. So far I have tried doing the same basic thing, loading the filtered items into a list then using AddRange to add them faster, and using the Visible property of the controls instead of adding and removing them. The fastest so far that I have found is using a temporary list, then listPanel.Controls.Clear(); and listPanel.Controls.AddRange(tmp); Every way I have tried has lots of flickering, something that is not present using Java Swing.

by DiscountPork via /r/csharp

Leave a Reply