3

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.

TxDeadhead
  • 43
  • 1
  • 6

2 Answers2

5

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;
        }
    }
competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • Sorry, been answering questions on C# thread, so forgot this was a VB question. btw: welcome to stack overflow. Keep in mind that if an answer helps you solve your question, you should click on the checkmark and up arrows next to the answer so that future visitors to this question know this is what helped you. – competent_tech Dec 13 '11 at 00:48
  • Not a problem, I translated it to VB. Thank you. I'd up arrow this, but the site doesn't like me yet. Need more Rep :-) – TxDeadhead Dec 13 '11 at 00:55
1

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.

TxDeadhead
  • 43
  • 1
  • 6