gpt4 book ai didi

c# - '...' 没有重载匹配委托(delegate) 'System.Windows.Forms.ItemCheckEventHandler'

转载 作者:行者123 更新时间:2023-11-30 17:43:31 25 4
gpt4 key购买 nike

看完this问题,对我来说很明显我写错了我的事件。但是,我不知道如何才能重写我使用 Object sender 编写的内容。我的事件将所选复选框中的文本添加到二维列表 (report),report 中的顺序必须与所选复选框的顺序相同。此外,一次最多只能选中两个复选框。这是事件:

void checkedListBox_ItemCheck(CheckedListBox chkdlstbx, ItemCheckEventArgs e)
{
int index = Convert.ToInt32(chkdlstbx.Tag);
if ((chkdlstbx.CheckedItems.Count == 0) && (e.CurrentValue == CheckState.Unchecked))
{
Var.report[index].Add(chkdlstbx.Text);
}
if ((chkdlstbx.CheckedItems.Count == 1) && (e.CurrentValue == CheckState.Checked))
{
Var.report[index].RemoveAt(0);
}
if ((chkdlstbx.CheckedItems.Count == 1) && (e.CurrentValue == CheckState.Unchecked))
{
if (chkdlstbx.SelectedIndex < chkdlstbx.CheckedIndices[0])
{
Var.report[index].Insert(0, chkdlstbx.Text);
}
else
{
Var.report[index].Add(chkdlstbx.Text);
}
}
if ((chkdlstbx.CheckedItems.Count == 2) && (e.CurrentValue == CheckState.Checked))
{
if (chkdlstbx.SelectedIndex == chkdlstbx.CheckedIndices[0])
{
Var.report[index].RemoveAt(0);
}
else
{
Var.report[index].RemoveAt(1);
}
}
if ((chkdlstbx.CheckedItems.Count == 2) && (e.CurrentValue == CheckState.Unchecked))
{
e.NewValue = CheckState.Unchecked;
}
updateReport();
}

它被这条线调用:

chkdlstbx.ItemCheck += new ItemCheckEventHandler(checkedListBox_ItemCheck);

如果有人可以帮助我使用对象重写我的事件,那就太棒了。我真的不确定我还能如何解决这个问题!

最佳答案

这应该足够了:

void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
{
CheckedListBox chkdlstbx = sender as CheckedListBox;
if (chkdlstbx == null)
{
throw new InvalidArgumentException();
}
....
}

关于c# - '...' 没有重载匹配委托(delegate) 'System.Windows.Forms.ItemCheckEventHandler',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30814772/

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