gpt4 book ai didi

c# - ObjectListView 全选复选框

转载 作者:行者123 更新时间:2023-11-30 18:17:10 26 4
gpt4 key购买 nike

我有一个带有一些选项卡的 ObjectListView,其中一个是作业编号。此作业编号选项卡从数据库中获取作业编号,并在每个作业编号旁边显示一个复选框。我的要求是我想在该作业编号选项卡上添加一个复选框。在选中该复选框时,它应该选择它下面的所有作业编号。即,将选中每个作业编号复选框。有什么办法可以做到这一点..我将分享一个屏幕截图以供引用.. enter image description here

最佳答案

你需要监听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);
}
}
}

关于c# - ObjectListView 全选复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44694599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com