This question might be considered a follow-up to Flickering in listview with ownerdraw and virtualmode.
I\'ve got a ListView
control in Virtu
Like This Answer in Here, though not sure but,
I think that ListView.BeginUpdate()
and ListView.EndUpdate()
will solve the problem.
MSDN Thread about This
Maybe In This Way :
protected override void OnDrawItem(DrawListViewItemEventArgs eventArgs)
{
ListView.BeginUpdate();
//Do Works Here
ListView.EndUpdate();
}
Another Alternative may be using a new Thread in BackgroundWorker
to Update the ListView...
I implemented this along with BeginUpdate()
/EndUpDate()
in my application and found it relatively faster than only the BeginUpdate()
/EndUpDate()
..
I found another working Solution at SO, a Helper class provided by Brian Gillespie
:
public enum ListViewExtendedStyles
{
///
/// LVS_EX_GRIDLINES
///
GridLines = 0x00000001,
///
/// LVS_EX_SUBITEMIMAGES
///
SubItemImages = 0x00000002,
///
/// LVS_EX_CHECKBOXES
///
CheckBoxes = 0x00000004,
///
/// LVS_EX_TRACKSELECT
///
TrackSelect = 0x00000008,
///
/// LVS_EX_HEADERDRAGDROP
///
HeaderDragDrop = 0x00000010,
///
/// LVS_EX_FULLROWSELECT
///
FullRowSelect = 0x00000020,
///
/// LVS_EX_ONECLICKACTIVATE
///
OneClickActivate = 0x00000040,
///
/// LVS_EX_TWOCLICKACTIVATE
///
TwoClickActivate = 0x00000080,
///
/// LVS_EX_FLATSB
///
FlatsB = 0x00000100,
///
/// LVS_EX_REGIONAL
///
Regional = 0x00000200,
///
/// LVS_EX_INFOTIP
///
InfoTip = 0x00000400,
///
/// LVS_EX_UNDERLINEHOT
///
UnderlineHot = 0x00000800,
///
/// LVS_EX_UNDERLINECOLD
///
UnderlineCold = 0x00001000,
///
/// LVS_EX_MULTIWORKAREAS
///
MultilWorkAreas = 0x00002000,
///
/// LVS_EX_LABELTIP
///
LabelTip = 0x00004000,
///
/// LVS_EX_BORDERSELECT
///
BorderSelect = 0x00008000,
///
/// LVS_EX_DOUBLEBUFFER
///
DoubleBuffer = 0x00010000,
///
/// LVS_EX_HIDELABELS
///
HideLabels = 0x00020000,
///
/// LVS_EX_SINGLEROW
///
SingleRow = 0x00040000,
///
/// LVS_EX_SNAPTOGRID
///
SnapToGrid = 0x00080000,
///
/// LVS_EX_SIMPLESELECT
///
SimpleSelect = 0x00100000
}
public enum ListViewMessages
{
First = 0x1000,
SetExtendedStyle = (First + 54),
GetExtendedStyle = (First + 55),
}
///
/// Contains helper methods to change extended styles on ListView, including enabling double buffering.
/// Based on Giovanni Montrone's article on
///
public class ListViewHelper
{
private ListViewHelper()
{
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr handle, int messg, int wparam, int lparam);
public static void SetExtendedStyle(Control control, ListViewExtendedStyles exStyle)
{
ListViewExtendedStyles styles;
styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
styles |= exStyle;
SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);
}
public static void EnableDoubleBuffer(Control control)
{
ListViewExtendedStyles styles;
// read current style
styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
// enable double buffer and border select
styles |= ListViewExtendedStyles.DoubleBuffer | ListViewExtendedStyles.BorderSelect;
// write new style
SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);
}
public static void DisableDoubleBuffer(Control control)
{
ListViewExtendedStyles styles;
// read current style
styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
// disable double buffer and border select
styles -= styles & ListViewExtendedStyles.DoubleBuffer;
styles -= styles & ListViewExtendedStyles.BorderSelect;
// write new style
SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);
}
}