Baro
Baro

Reputation: 5520

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 ?

Upvotes: 0

Views: 308

Answers (1)

mm8
mm8

Reputation: 169340

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)

Upvotes: 1

Related Questions