TxD*_*ead 2 vb.net controls checkedlistbox tri-state-logic
我需要一些帮助,而且我的头撞在墙上.我有一个使用三态的应用程序CheckedListBox.我将这三种状态用于特定目的:
已检查表示技术执行了操作未选中表示技术人员未执行操作"不确定"表示技术人员未执行操作,因为这是不必要的.
我需要能够切换,鼠标从Checked到Unchecked到Indeterminate to Checked.如果我正在使用a CheckBox并且ThreeState被设置为True,那么这正是将要发生的事情,但似乎在CheckedListBox通过代码设置Indeterminate状态的唯一方法.
有人能告诉我该做什么吗?令我难以置信的是,这不是你可以设置的财产CheckBox.
我认为是什么让我觉得以前似乎没有人需要这个功能.我在Google上没有发现任何人如何做到这一点,或者提出问题.
我不认为控件中有一个属性来控制这种行为,但它很容易在代码中实现:
void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
switch (e.CurrentValue)
{
case CheckState.Checked:
e.NewValue = CheckState.Unchecked;
break;
case CheckState.Indeterminate:
e.NewValue = CheckState.Checked;
break;
case CheckState.Unchecked:
e.NewValue = CheckState.Indeterminate;
break;
}
}
Run Code Online (Sandbox Code Playgroud)