I have a listview that uses custom cell colors, but when I set a background image in the listview, the custom cell colors will not appear anymore. I tried to remove the background image temporarily (when assembling the list) and restore it after applying cell colors. This results in no custom colors but shows the background. I would like to combine these 2 listview properties if possible.
My code for setting/removing background image:
list.BackgroundImage = Properties.Resources.bgalpha;
list.BackgroundImage = null;
A part of my code for setting custom cell colors:
for (int i = 0; i < kavels.Count(); i++ )
{
if (list.Items[i].SubItems[1].Text != "0")
{
list.Items[i].UseItemStyleForSubItems = false;
list.Items[i].SubItems[1].BackColor = Color.LightGreen;
}
}
Here are two screenshots:
List view with background: http://i.imgur.com/aHUXAVh.png
List view without background: http://i.imgur.com/sO83wTP.png
I also tried making a PictureBox with a transparent background along with a png image with transparency on top of the ListView, but that also didn't work obviously.
You have two options:
Panel
or aPictureBox
with a semi-transprent Image. For this to work you would have to make it sit inside the ListView, so that it is theParent
of the overlay.But that will make the
Listview
non-clickable. - Another problem with this is that it will slightly color the text, so it won't look quite right.ListView
toOwnerDraw = true
and add code to do the drawing yourself.Here is an example, non-scrolled and scrolled:
Note that the original
BackgroundImage
shines through the emtpy space to the right.If you owner-draw a ListView in Details mode you need to code events to draw subitems and headers; note the class level variable to hold the itemHeight; this assumes they all have the same Height .. The other one is need for horizontal scrolling.
Here is the code to set the colors in the
ListViewItem lvi
for the example:Note that the code assumes your background is one large image and no tiling is involved! Also the code works only if you don't have groups!
ObjectListView -- an open source wrapper around a standard .NET
ListView
-- providesImageOverlays
and true background images too. They both work with colour cells.