Please help with my query.

Is it possible to add images to subitems in a listview control I have looked at using the stateimagelist, but this only applies to the item, and has only 2 states, checked or unchecked.

I need to have different images for three subitems.

Thanks,



Re: Windows Forms General Adding images to subitems in a listview control

Anindya Maiti

No ,its not possible.




Re: Windows Forms General Adding images to subitems in a listview control

bb35

It is possible to add images to subitems in a ListView control, but you'll have to customize drawing for the ListView. Set OwnerDraw to true, and handle DrawColumnHeader, DrawItem and DrawSubItem events. As an example, if I want to put a blue rectangle in the second column, for each item, I would handle these events in the following way:

private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)

{

e.DrawBackground();

e.DrawText();

}

private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)

{

if (e.ColumnIndex == 1)

e.Graphics.FillRectangle(new SolidBrush(Color.Blue), e.Bounds);

else

e.DrawDefault = true;

}

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)

{

e.DrawDefault = true;

}






Re: Windows Forms General Adding images to subitems in a listview control

ReneeC

I just tried this method and found it to be very deficient. It's impressive until you put your mouse up to the listview only to find out that the items dissapear and are not refreshed when the mouse is over the items. It's most unprofessional.

However, removing this:

private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)

{

e.DrawBackground();

e.DrawText();

}

Produced a much more satisfactory result in what was a cursory test.