如何修改listview表头的颜色啊?如何修改listview表头的颜色
1个回答
推荐于2016-11-04 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517194
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
这个应该很简单吧,你直接在绑定ListView数据项的时候将第一行设置其前景色或后景色。
private void LoadMockData()
{
listView1.Items.Clear();
var users = new List<User> {
new User { Id = 1, Name = "Jim", Age = 22, Sex = "Male" },
new User { Id = 2, Name = "Tom", Age = 21, Sex = "Male" },
new User { Id = 3, Name = "Henry", Age = 23, Sex = "Male" },
new User { Id = 4, Name = "Rah", Age = 24, Sex = "Male" },
new User { Id = 5, Name = "Ram", Age = 22, Sex = "Female" },
new User { Id = 6, Name = "Loha", Age = 25, Sex = "Male" }
};
int i = 1;
foreach (User user in users)
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.Text = user.Id.ToString();
item.SubItems.Add(user.Name);
item.SubItems.Add(user.Age.ToString());
item.SubItems.Add(user.Sex);
if (i == 1)
{
item.BackColor = Color.Aqua;
item.ForeColor = Color.Red;
}
listView1.Items.Add(item);
i++;
}
}
private void LoadMockData()
{
listView1.Items.Clear();
var users = new List<User> {
new User { Id = 1, Name = "Jim", Age = 22, Sex = "Male" },
new User { Id = 2, Name = "Tom", Age = 21, Sex = "Male" },
new User { Id = 3, Name = "Henry", Age = 23, Sex = "Male" },
new User { Id = 4, Name = "Rah", Age = 24, Sex = "Male" },
new User { Id = 5, Name = "Ram", Age = 22, Sex = "Female" },
new User { Id = 6, Name = "Loha", Age = 25, Sex = "Male" }
};
int i = 1;
foreach (User user in users)
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.Text = user.Id.ToString();
item.SubItems.Add(user.Name);
item.SubItems.Add(user.Age.ToString());
item.SubItems.Add(user.Sex);
if (i == 1)
{
item.BackColor = Color.Aqua;
item.ForeColor = Color.Red;
}
listView1.Items.Add(item);
i++;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询