Reputation: 45
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..
Upvotes: 3
Views: 1052
Reputation: 9610
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);
}
}
}
Upvotes: 1