2

Is it possible to insert programmatically a line separator between two rows in a Winform c# ListView ?

Like that for example :

enter image description here

Fabien
  • 458
  • 3
  • 17
  • Probable duplicate of [How to add border to items in a listview control using C#?](http://stackoverflow.com/questions/32693837/how-to-add-border-to-items-in-a-listview-control-using-c#32694195) – TnTinMn Jan 16 '17 at 14:41
  • 1
    It's actually a good lead I think but I did not succeed to do it with... Is there a expert who can find a solution from it ? – Fabien Jan 16 '17 at 15:54

1 Answers1

2

Going off of the answer provided in the comments above. You need to hook into the DrawItem event and draw the line at the bottom after whatever item you want is drawn. Here I've drawn a line after item with Text == "2" is drawn:

private void ListView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
    e.DrawDefault = true;

    if (e.Item.Text == "2")
    {
        e.Graphics.DrawLine(Pens.Black, e.Bounds.Left, e.Bounds.Bottom, e.Bounds.Right, e.Bounds.Bottom);
    }
}

You may need to draw the line underneath multiple items if more than one item is placed on a row in your ListView.

enter image description here

jaredbaszler
  • 3,941
  • 2
  • 32
  • 40