更改所选列表视图项的背景颜色 [英] Change background color of selected listview item

查看:91
本文介绍了更改所选列表视图项的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想更改所选的列表视图项,但我遇到了一些问题。所选行的颜色不会改变。以下是我的代码,



Hi I want to change the selected listview item but i have encountered with some problem. The color of the selected row wont change. Below are my codes,

private void onImportanceClick(object sender, RoutedEventArgs e) {

            string date = label5.Content.ToString();

            DateTime dateNow = DateTime.Now;

            DateTime dateOld = Convert.ToDateTime(date);

            TimeSpan diff = dateNow - dateOld;

            double newDiff = diff.TotalDays;

            int dayDiff = Convert.ToInt32(newDiff);

 

            foreach(ListViewItem li in ScheduleListView.Items)

            {

                if (dayDiff > 10)

                {

                    li.Background = Brushes.Green;

                }

                else if (dayDiff < 10 && newDiff > 3)

                {

                    li.Background = Brushes.Yellow;

                }

                else if (dayDiff < 3)

                {
                  li.Background = Brushes.Red;

                }

                else { }
            }

}

推荐答案

访问这些链接,希望它有用

http://stackoverflow.com/questions/91747/background-color-of-a-listbox-item-winforms [ ^ ]

http://stackoverflow.com/questions/15431097/listbox-wpf -item-background-color [ ^ ]



问候

Sameer
Visit these links, hope it is helpful
http://stackoverflow.com/questions/91747/background-color-of-a-listbox-item-winforms[^]
http://stackoverflow.com/questions/15431097/listbox-wpf-item-background-color[^]

Regards
Sameer


试试这个:



Try this:

private void FormPatient_Load(object sender, EventArgs e)
{
	lv.OwnerDraw = true;
}

private void lv_DrawItem(object sender, DrawListViewItemEventArgs e)
{
	if (e.Item.Selected)
	{
		lvix.BackColor = Color.Maroon;
		lvix.ForeColor = Color.White;
	}
	else
	{
		lvix.BackColor = Color.White;
		lvix.ForeColor = Color.Black;
	}

	e.DrawBackground();
	e.DrawText();
}


这篇关于更改所选列表视图项的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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