ObjectListView Select all checkBox
I have an ObjectListView with some tabs on it, one of which is the job number. This Job Numbers tab selects the job number from the database and displays it with a check box next to each job number. My requirement is that I want to add a checkbox on this Job Number tab. By checking this box, it should select all the job numbers below it. that is, the check box of each job number will be selected. Is there any way I could achieve this .. I'll share with Screen Shot for reference ..
+3
source to share
1 answer
You need to listen to the checkitem event, then find which event was checked, and then check the ones below. (I assumed that jobs with a "job number"> than the checked item are below and should 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);
}
}
}
0
source to share