的WinForms - 如何交替排在ListView控件的颜色? [英] Winforms - How to alternate the color of rows in a ListView control?

查看:132
本文介绍了的WinForms - 如何交替排在ListView控件的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#的WinForms(3.5)。

是否有可能设置行的颜色,自动交替在ListView?

或者我需要一个新的行添加到列表视图每次手动设置行的颜色?

基于一个 MSDN 文章

的手动的方法是这样的:

  //交替行的颜色
如果(我%2 == 0)
{
    lvi.BackColor = Color.LightBlue;
}
其他
{
    lvi.BackColor = Color.Beige;
}
 

解决方案

我恐怕是的WinForms的唯一途径。 XAML允许这种通过使用样式虽然。

Using C# Winforms (3.5).

Is it possible to set the row colors to automatically alternate in a listview?

Or do I need to manually set the row color each time a new row is added to the listview?

Based on a MSDN article the manual method would look like this:

//alternate row color
if (i % 2 == 0)
{
    lvi.BackColor = Color.LightBlue;
}
else
{
    lvi.BackColor = Color.Beige;
}

解决方案

I'm afraid that is the only way in Winforms. XAML allows this through use of styles though.

这篇关于的WinForms - 如何交替排在ListView控件的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆