ObjectListView 全选复选框 [英] ObjectListView Select all checkBox

查看:24
本文介绍了ObjectListView 全选复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些选项卡的 ObjectListView,其中一个是工作编号.此作业编号选项卡从数据库中获取作业编号,并在每个作业编号旁边显示一个复选框.我的要求是我想在作业编号"选项卡本身上添加一个复选框.选中该复选框后,它应选择其下方的所有作业编号.即,将选中每个作业编号复选框.有什么办法可以做到这一点..我将分享一个屏幕截图以供参考..

I have an ObjectListView with some Tabs on it, One of them being Job number. This Job number tabs fetches Job number from database and displays it with a checkbox beside each job number. My requirement is that i want to add a check box on that Job Number tab itself. On checking that check box, It should select all the job numbers below it. i.e, each job number check box will be selected.. Is there any way i could achieve this.. i will share a Screen Shot for reference..

推荐答案

你需要监听checkitem事件,然后找出哪个事件被选中,然后再检查这个下面的事件.(我假设工作编号"> 比选中项目的工作在下面,需要检查.)

You need to listen to the checkitem event, then find which event was checked and then check the ones below this. (I have assumed that the jobs with a "Job Number" > than the checked item are below and need to be checked.)

private void objectListView1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
    //First we need to cast the received object to an OLVListItem
    BrightIdeasSoftware.OLVListItem olvItem = e.Item as BrightIdeasSoftware.OLVListItem;
    if (olvItem == null)
        return;    //Unable to cast

    //Now we can cast the RowObject as our class
    MyClass my = olvItem.RowObject as MyClass;
    if (my == null)
        return;   //unable to cast

    //We retrieve the jobnumber.  So this is the job number of the item clicked
    int jobNumber = my.Job; 

    //Now loop through all of our objects in the ObjectListView
    foreach(var found in objectListView1.Objects)
    {
        //cast it to our type of object
        MyClass mt = found as MyClass;

        //Compare to our job number, if greater then we check/uncheck the items
        if (mt.Job > jobNumber)
        {
            if (e.Item.Checked)
                objectListView1.CheckObject(mt);
            else
                objectListView1.UncheckObject(mt);
        }
    }
}

这篇关于ObjectListView 全选复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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