Search code examples
wpfvb.netcheckboxthreestate

WPF/VB How to set a threestate checkbox (or nullable boolean) to Nothing(null)


The title explain all itself. For VB the keyword Nothing is the same as False.

This code verify if checkbox is a three state checkbox, and set the default value, indeterminate if is a "three state", and false if is not.

myThreeStateChkbox.IsChecked = If(myThreeStateChkbox.IsThreeState, Nothing, False)

The result is the same, always False. How can I set the indeterminate state ?


Solution

  • What about New Nullable(Of Boolean)?

    myThreeStateChkbox.IsChecked = If(myThreeStateChkbox.IsThreeState, New Nullable(Of Boolean), False)
    

    Or shorter just New Boolean?:

    myThreeStateChkbox.IsChecked = If(myThreeStateChkbox.IsThreeState, New Boolean?, False)