在 CheckedListBox 中用鼠标设置不确定状态

发布于 2024-12-20 19:08:40 字数 470 浏览 0 评论 0原文

我需要一些帮助,但我正在用头撞墙。我有一个使用三态 CheckedListBox 的应用程序。我将这三种状态用于特定目的:

选中意味着技术执行了操作 未选中意味着技术未执行该操作 不确定意味着技术没有执行该操作,因为这是不必要的。

我需要能够根据需要使用鼠标从“已选中”到“未选中”到“不确定”到“已选中”进行切换。如果我使用 CheckBox 并将 ThreeState 设置为 True,这正是会发生的情况,但似乎设置的唯一方法CheckedListBox 中的不确定状态是通过代码实现的。

有人可以告诉我该怎么做吗?令我难以置信的是,它不是一个可以像在 CheckBox 中那样设置的属性。

我认为让我困惑的是以前似乎没有人需要这个功能。我在谷歌上没有找到任何关于如何做到这一点或提出这个问题的信息。

I need some assistance and I'm beating my head against the wall. I have an application that uses a tri-state CheckedListBox. I use the three states for specific purposes:

Checked means tech performed an action
Unchecked means the tech didn't perform the action
Indeterminate means that the tech didn't perform the action because it was unnecessary.

I need to be able toggle, with the mouse from Checked to Unchecked to Indeterminate to Checked as necessary. If I were using a CheckBox and ThreeState were set to True, this is exactly what would happen, but it appears that the only way to set the Indeterminate state in the CheckedListBox is through code.

Could someone give me an idea of what to do? It boggles my mind that it's not a Property you can set like you can in CheckBox.

I think what throws me is that no one seems to have needed this functionality before. I have found nothing on Google about how one might do this, or asking the question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何其悲哀 2024-12-27 19:08:41

我认为控件中没有属性来控制此行为,但在代码中很容易实现:

    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;
        }
    }

I don't think that there is a property in the control to control this behavior, but it is easy to implement in code:

    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;
        }
    }
不交电费瞎发啥光 2024-12-27 19:08:41

我将所提供的建议从 C# 翻译成 VB,如下所示,

Private Sub CheckedListBoxCriteria_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBoxCriteria.ItemCheck

Select Case e.CurrentValue
   Case CheckState.Checked
      e.NewValue = CheckState.Unchecked
      Exit Select

   Case CheckState.Indeterminate
      e.NewValue = CheckState.Checked
      Exit Select

   Case CheckState.Unchecked
      e.NewValue = CheckState.Indeterminate
      Exit Select
   End Select
End Sub

效果非常好。我发誓我尝试过类似的事情,但我没有做对。但这有效。非常感谢。就这么简单。有一天我会解决这个问题。自学包括提出一个想法并进行挖掘,直到找到线索。

I translated the offered suggestion from C# to VB as follows

Private Sub CheckedListBoxCriteria_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBoxCriteria.ItemCheck

Select Case e.CurrentValue
   Case CheckState.Checked
      e.NewValue = CheckState.Unchecked
      Exit Select

   Case CheckState.Indeterminate
      e.NewValue = CheckState.Checked
      Exit Select

   Case CheckState.Unchecked
      e.NewValue = CheckState.Indeterminate
      Exit Select
   End Select
End Sub

Worked like a charm. I would have sworn I tried something similar to that, but I didn't get it right. But this worked. Thank you so very much. So simple. Someday I'll figure this out. Teaching myself consists of coming up with an idea and digging around until I find a clue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文