在列表视图中更改选中项目的背面颜色 [英] changing the back color of checked item in list view

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

问题描述

我有一个列表视图,其中的视图为详细信息,并且我已将复选框选项设置为true,将全行选择设置为true.现在,当我选中复选框时,对应的行背景色应更改为蓝色(整个行)..如何执行此操作?


在此先感谢,

I have a listview with view as details and i have set checkbox option to true, i have set full row select to true. now when i check the checkbox, corresponding row backcolor should change to blue(entire row)..how to do this??


thanks in advance,

推荐答案

这将完成工作.
谢谢,

this will do the work..i posted it here bcos it may help some one

thanks,

void ListView1_ItemCheck(object sender, ItemCheckEventArgs e)
{
    try
    {
        listView1.FullRowSelect=true;
        if(listView1.Items[e.Index].Checked==false)
        {
            listView1.Items[e.Index].BackColor=Color.Aqua;
        }
        else
        {
            listView1.Items[e.Index].BackColor=Color.White;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


如果您在WPF中,则可能绑定到了项目列表.向模型视图对象添加一个属性,该属性表示背景色的行,基于表示为选中状态的属性计算颜色,然后将该新属性绑定到项目模板中的背景色.
If you''re in WPF you are probably binding to a list of items. Add a property to the model-view object that represents rows for background colour, calculate a colour based on the property that is represented as the checked state, and bind that new property to the background colour in the item template.


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

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