gpt4 book ai didi

c# - .NET 列表框 : in ItemChecked event know if item was clicked

转载 作者:太空宇宙 更新时间:2023-11-03 20:34:06 24 4
gpt4 key购买 nike

我的 Winforms 应用程序中有一个 ListBox,我需要处理 ItemChecked,因为每次用户点击一个项目时我需要一些东西。问题是我还需要在表单的其他一些事件中更改 Checked 属性。在那些情况下,我需要避免做那些事情。

例子:

private void listBox1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (true) //Should check if item was clicked.
{
//Do some stuff
}
else //If the event was fired because I changed the Checked property from the code
{
//Do some other stuff
}
}

谢谢

最佳答案

如果我对您的理解正确,我认为您想在幕后更改 Checked 属性时取消订阅 ItemCheck 事件(即用户没有导致 Checked 属性更改)。

例如:

public void SetupListBoxEnables()
{
// Do not listen for Checked change events
listBox1.ItemCheck -= listBox1_ItemChecked;
// Change a bunch of Checked properties
// ....

// Listen again for Checked change events
listBox1.ItemCheck += listBox1_ItemChecked;
}

关于c# - .NET 列表框 : in ItemChecked event know if item was clicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5903770/

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