作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
看完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/
我有一个 ListView,它在第一列上有复选框。在为自定义排序编写一些代码时(当用户单击列标题时),我遇到了一些奇怪的行为。 当用户单击列标题时,我使用 ColumnClickEventHandle
我正在寻找 CheckedListBox 的事件,该事件在项目的选中状态更改后触发。 ItemCheckEventHandler 对我不利,因为它会在应用新状态之前触发。 谢谢! 最佳答案 如果您要查
看完this问题,对我来说很明显我写错了我的事件。但是,我不知道如何才能重写我使用 Object sender 编写的内容。我的事件将所选复选框中的文本添加到二维列表 (report),report
我是一名优秀的程序员,十分优秀!