C# - ListView 줄마다 다른 색으로 칠하기


ListView에서 줄마다 다른 배경색을 사용하면 좀 더 읽기 좋고 이뻐집니다.

public void SetAlternatingRowColors(ListView lst, Color color1, Color color2)
{
    //loop through each ListViewItem in the ListView control
    foreach (ListViewItem item in lst.Items)
    {
        if ((item.Index % 2) == 0)
            item.BackColor = color1;
        else
            item.BackColor = color2;
    }
}

 

광고

댓글 남기기