colour is not Highlighted in listviewitem subitems
I am using this code to hide the first three subitems of even numbers .
For ex
there are 2 listviewitem
1) 132 |123 |123 |123 |Buy |11 |11 |11 |11
2) 132 |123 |123 |123 |Sell|22 |22 |22 |22
I am displaying them like this in the listview
132 |123 |123 |123 |Buy |11 |11 |11 |11
|Sell|22 |22 |22 |22
I want to highlight the color of Buy as Green and sell as Red
I am using this code to display it is highlighting green but not for red
int iRecords = 0;
int iDate = 0;
int iRecords1 = 0;
using (var sr = File.OpenText(destination + "\\Calc.txt"))
{
string line;
bool flag = true;
int i = 0;
while ((line = sr.ReadLine()) != null)
{
string[] reader2 = line.Split(',');
string Date = reader2[0];
string Name = reader2[1];
string Sym = reader2[2];
double Buy = Convert.ToDouble(reader2[3]);
double Sell = Convert.ToDouble(reader2[4]);
double rateBuy = Convert.ToDouble(reader2[5]);
double rateSell = Convert.ToDouble(reader2[6]);
ListViewItem lItem = new ListViewItem();
if (i == 0)
{
lItem = listviewrates.Items.Insert(iRecords, Date.ToString());
date.Text = Date;
lItem.UseItemStyleForSubItems = false;
lItem.SubItems.Add(Name.ToString());
lItem.SubItems.Add(Sym.ToString());
lItem.SubItems.Add(Buy.ToString(), Color.White, Color.Green, lItem.Font);
lItem.SubItems.Add(rateBuy.ToString());
i = 2;
iRecords++;
}
if (i == 2)
{
lItem = listviewTargets.Items.Insert(iRecords, "");
//iRecords = iRecords - 1;
lItem.SubItems.Add("");
开发者_Go百科 lItem.SubItems.Add("");
lItem.SubItems.Add(Sell.ToString(), Color.White, Color.Red, lItem.Font);
lItem.SubItems.Add(rateSell.ToString());
i = 0;
iRecords++;
}
}
}
Can any one please say me how to highlight red color for sell.
Thanks In Advance.
For your green items, you did:
lItem.useItemStyleForSubItems = false;
You need to add the property for the red item, too, since lItem is a new object.
if (i == 2)
{
lItem = listviewTargets.Items.Insert(iRecords, "");
//Fix here:
lItem.useItemStyleForSubItems = false;
lItem.SubItems.Add("");
lItem.SubItems.Add("");
lItem.SubItems.Add(Sell.ToString(), Color.White, Color.Red, lItem.Font);
lItem.SubItems.Add(rateSell.ToString());
i = 0;
iRecords++;
}
精彩评论