When populating a listview it is always a good idea to call BeginUpdate before adding/removing/clearing items. Otherwise the control will attempt to repaint on every change, greatly reducing the overall performance.
A question often asked is what to do with Listbox and Combobox classes, which in Compact Framework do not expose these methods. Apparently it is quite easy to emulate missing methods.
The secret is in WM_SETREDRAW message. It tells the window to stop updating itself. The actual implementation is up to the window class, but luckily in case of Combobox and Listbox this message is handled and provides expected results. Here is what is says in remarks part of the message description:
The window manager provides no default processing for this message. However, certain controls do support this message, list box, tree view, and combo box
Armed with this knowledge, we find it almost trivial to write the missing methods:
public class UIHelper
{
public static IntPtr GetHandle(Control ctl)
{
ctl.Capture = true;
IntPtr ret = Win32Window.GetCapture();
ctl.Capture = false;
return ret;
}
public static void EnableDisableUpdates(Control ctl, bool bDisable)
{
if ( ! (ctl is ListBox) && ! (ctl is ComboBox) )
throw new NotSupportedException("Control must be either listbox or combobox");
IntPtr hWnd = GetHandle(ctl);
Win32Window.SendMessage(hWnd, WM_SETREDRAW, bDisable? 0: 1, 0);
}
const int WM_SETREDRAW = 0x0b;
}
Notice
This code uses Win32Window class found in
OpenNETCF SDF. If you don't want to use SDF, the P/Invoke defionitions for GetCapture and SendMessage can be found
here.