I tried to add text color to any sub item in the listview by the index that the method get from the array
for (int i = 0; i < sizes.Length; ++i)
{
if (sizes[i] == 1)
{
Item.SubItems.Add("In Stock");
}
else if (sizes[i] == 0)
{
Item.SubItems.Add("Out Of Stock");
}
else if (sizes[i] == 2)
{
Item.SubItems.Add("Less Than 3");
}
else if (sizes[i] == 5)
{
Item.SubItems.Add("Less Than 5");
}
else if (sizes[i] == 10)
{
Item.SubItems.Add("Less Than 10");
}
}
ProductListView.Items.Add(Item);
}
if the size in stock the subitem color change to green and if the size is out of stock the subitem color will change to red
thanks
The Add
method returns the subItem,
So you can change the subItem color like this:
var subItem = Item.SubItems.Add("In Stock");
subItem.ForeColor = Color.Green;
// subItem.BackColor = Color.Red;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.