Tag Archives: ListBox

How to draw Listbox items with alternative background colors

Some people find it easier to read large amount of data when the rows have an alternative background color instead of always the same. This is called Zebra Striping.

For this example we will look into implementing this technique for our ListBox control so it will look similar to this:
Listbox zebra striping

First we need to ensure that the ListBox.DrawMode property is set to DrawMode.OwnerDrawFixed. This can be accomplished by either changing the property in the properties window or by placing listBox1.DrawMode = DrawMode.OwnerDrawFixed; in your form’s constructor or any of the load events.

Then we need to handle the ListBox’s DrawItem event so we can change the colors as we like.

And we are done ! Feel free to modify the example to suit your needs.

ListBox selected item custom background and text color

This snippet will allow you to set a custom color for your ListBox’s selected item background as well as the selected items text color.

First make sure that your ListBox’s DrawMode is set to OwnerDrawFixed. This can either by done in the controls properties window or by calling listBox1.DrawMode = DrawMode.OwnerDrawFixed;

Then we need to handle the ListBox’s DrawItem event which is where we will be doing the changes to the selected items.