listviewitem 子项中的颜色未突出显示
我使用此代码来隐藏偶数的前三个子项。
例如,
有 2 个 listviewitem
1) 132 |123 |123 |123 |Buy |11 |11 |11 |11
2) 132 |123 |123 |123 |Sell|22 |22 |22 |22
我这样显示它们在列表视图中,
132 |123 |123 |123 |Buy |11 |11 |11 |11
|Sell|22 |22 |22 |22
我想将“购买”的颜色突出显示为绿色 并以红色出售
我使用此代码来显示它突出显示绿色但不突出显示红色
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("");
lItem.SubItems.Add("");
lItem.SubItems.Add(Sell.ToString(), Color.White, Color.Red, lItem.Font);
lItem.SubItems.Add(rateSell.ToString());
i = 0;
iRecords++;
}
}
}
任何人都可以告诉我如何突出显示红色以进行出售。
提前致谢。
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("");
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于绿色项目,您做了:
您还需要添加红色项目的属性,因为 lItem 是一个新对象。
For your green items, you did:
You need to add the property for the red item, too, since lItem is a new object.