我有一个带有一些Tabs的ObjectListView,其中一个是Job number。此作业编号选项卡从数据库中提取作业编号,并在每个作业编号旁边显示一个复选框。我的要求是我想在该“职务编号”选项卡上添加一个复选框。在选中该复选框时,它应选择它下面的所有作业号。即,将选中每个作业号复选框.. 有什么方法可以实现这一点..我将分享一个屏幕截图供参考..
答案 0 :(得分:0)
您需要收听checkitem事件,然后查找已检查的事件,然后检查下面的事件。 (我假设工作编号"">的工作比检查项目低,需要检查。)
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);
}
}
}