Wednesday, April 8, 2009

Remove flicker in listbox C#

I read over 100 articles on the web just one was able to help me and that too was ignored by others in the discussion.

Well, if you are adding less number of items to a listbox then
listbox1.beginupdate()
listbox1.add(item);
listbox1.endupdate();

should work for you just fine. There shall be no flicker.
using doublebuffered user control / form may also solve the problem. In some cases

this.SetStyle(ControlStyles.UserPaint  ControlStyles.OptimizedDoubleBuffer 
ControlStyles.AllPaintingInWmPaint ControlStyles.SupportsTransparentBackColor,
true);
may also work.

but in my case the data was coming at a very high speed and high quantity and I had to display this large amount of data in an owner drawn list box.

this.SuspendLayout();
foreach (DataItem ditem in ditems)
{
listbox1.Items.Add(ditem);
}
this.ResumeLayout();


the above code helped me in getting a pretty smooth layout.

hope it helps
Vaibhav Chugh

No comments: