C# - listview 에서 subitem 색깔 변경하기


출처 : http://www.vbforums.com/showthread.php?s=&postid=1635115#post1635115

You need to set the UseItemStyleForSubItems property of the parent ListViewItem to false before the individual subitem settings will have any effect, i.e.

private void LoadData(DataTable table, ListView list)
{
    ListViewItem item;
    ListViewItem.ListViewSubItem subItem;

    list.Items.Clear();
    foreach(DataRow row in table.Rows)
    {
        item = list.Items.Add(row[0].ToString());
        item.UseItemStyleForSubItems = false;

        for(int i = 1; i < table.Columns.Count; i++)
        {
            subItem = item.SubItems.Add(row[i].ToString());

            if( subItem.Text.Equals("Produce") == true )
            subItem.ForeColor = Color.Red;
        }
    }
}

 

광고

댓글 남기기