Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObjectListView Select all checkBox

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..enter image description here

like image 500
Ksingh Avatar asked Apr 21 '26 08:04

Ksingh


1 Answers

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);
        }
    }
}
like image 182
jason.kaisersmith Avatar answered Apr 22 '26 23:04

jason.kaisersmith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!