fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Getting the status of a WPF checkbox in X#

Getting the status of a WPF checkbox in X# 2 months 2 weeks ago #8330

  ic2's Avatar Topic Author ic2 Offline Posts: 499
I've already solved the issue which I will describe here but I just wonder why I have to do it as it is done now.

I am working on my Excel reader and changed from .Net Core to Vulcan dialect so I can create a DBF from the Excel sheet. On the WPF form I added a checkbox with name cbisheader and if checked the program knows that the first row in the Excel contains the headers.

So I used:

If cbisheader:Checked

This is the VO/Vulcan way but it doesn't work. I get:

Error XS0079 The event 'System.Windows.Controls.Primitives.ToggleButton.Checked' can only appear on the left hand side of += or -=

After some search (somebody wrote "Checked here is an event, not a bool, that happens when it is checked. You need a different property - presumably IsChecked.") I changed it to:

If cbisheader:isChecked

and got:

Error XS0266 Cannot implicitly convert type 'logic?' to 'logic'. An explicit conversion exists (are you missing a cast?)

Below what finally worked. But it doesn't make sense to me. I would expect the above should work, or this one but with a double =.

If cbisheader:isChecked=True

What is the logic behind this "logic"?

Dick

Please Log in or Create an account to join the conversation.

Getting the status of a WPF checkbox in X# 2 months 2 weeks ago #8331

  Chris's Avatar Chris Offline Posts: 1181
Hi Dick,

This is because apparently IsChecked is not of normal LOGIC type, but it returns a special type, a nullable logic. This is different in the sense it provides 3 states, yes, no and "don't know" (when the value is NULL).

In order to use such a type, you'd normally need to check first:

IF cbisheader:IsChecked:HasValue // returns false if it is NULL

and only if the above returns TRUE, then you can be sure that the var does hold a LOGIC value (and not NULL), and you can access this value with

IF cbisheader:IsChecked:Value // true or false

or with the (cast) that you used before.

The reason behind introducing Nullable types, is to provide this "do not know" value to common types, likes ints. So, for example, a nullable int can have all the values a normal int has, but it can also hold NULL, which may mean that the value has not be assigned yet, when reading it from a database the contents where corrupted, things like that. With a normal int, we would need to use for example by convention a value of -1 to denote "invalid vale", but this causes all sorts of problems, thus the introduction of nullable types in .Net.

Now, why on earth should a CheckBox have a "don't know" value in addition to checked and unchecked, I have no idea, you'd need to ask the people who designed WPF about this :)
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Getting the status of a WPF checkbox in X# 2 months 2 weeks ago #8332

  ic2's Avatar Topic Author ic2 Offline Posts: 499
Hello Chris,

Thanks for the lesson. I can imagine the "don't know" - it is not uncommon, given the privacy rules, to see questions like Male/Female expanded with "don't want to say". So the nullable logic is the logic? I understand.

Dick

Dick

Please Log in or Create an account to join the conversation.

Getting the status of a WPF checkbox in X# 2 months 2 weeks ago #8333

  lumberjack's Avatar lumberjack Offline Posts: 465
Hi Dick,

ic2 wrote: I've already solved the issue which I will describe here but I just wonder why I have to do it as it is done now.

Well I solved this long time ago, remember you can have a CheckBox with no initial value set. .NET don't allow NULL booleans or DateTime values.

I wrote this little #command to solve the problem based on the c# "?" to define Nullables:
#command LOCAL <v0,...> AS <typ>? => ;
                   LOCAL <v0> AS System.Nullable\< <typ> \>

FUNCTION Start() AS VOID
    LOCAL lNull, lTrue, lFalse AS LOGIC?
    lTrue := TRUE
    lFalse := FALSE
    ?"Has value : ", lNull:HasValue, lTrue:HasValue, lFalse:HasValue
    ?"   Values : ", lNull:, lTrue, lFalse, e"Note only lTrue and lFalse displayed, lNull has no value, hence empty \"\""
    ?"  Is null : ", lNull == NULL, lTrue == NULL, lFalse == NULL
    ?" Is false : ", lNull == FALSE, lTrue == FALSE, lFalse == FALSE
    ?"  Is true : ", lNull == TRUE, lTrue == TRUE, lFalse == TRUE
RETURN

Hope this helps...
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

Getting the status of a WPF checkbox in X# 2 months 2 weeks ago #8339

  wriedmann's Avatar wriedmann Away Posts: 1573
Hi Dick,

this reflects the SQL logic: a logic field in a SQL table can be true, false or null.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Getting the status of a WPF checkbox in X# 2 months 2 weeks ago #8344

  FFF's Avatar FFF Away Posts: 577
Yeah - and if the unknown moron who coined the "null" instead of "unknown", or better, "not assigned", had known better, many, many misconceptions could have been avoided...

Please Log in or Create an account to join the conversation.

Getting the status of a WPF checkbox in X# 2 months 2 weeks ago #8346

  ic2's Avatar Topic Author ic2 Offline Posts: 499
Hello Karl,

Yeah - and if the unknown moron who coined the "null" instead of "unknown", or better, "not assigned", had known better, many, many misconceptions could have been avoided...


Probably the same guy who thought it was a good idea to make indexes zero based :evil:.

Dick

Please Log in or Create an account to join the conversation.

Getting the status of a WPF checkbox in X# 2 months 2 weeks ago #8353

  lumberjack's Avatar lumberjack Offline Posts: 465
Haha,

ic2 wrote:

Yeah - and if the unknown moron who coined the "null" instead of "unknown", or better, "not assigned", had known better, many, many misconceptions could have been avoided...

Probably the same guy who thought it was a good idea to make indexes zero based :evil:.

Well a decimal system means 10 digits, not 11 like the way the average person think...
0...9 = 10 Numbers,
1...10 = 10 Numbers // Ask anybody with this mindset and they will tell you, oh yes 0 is also a number. Therefore 1...10 means actually 0...10 = 11 Numbers, it is actually the only Number system that uses this concept, 0...1 = 2 Numbers, 0...7 = 8 Numbers, 0..15 = 16 Numbers, 0...127 = 128 Numbers, 0..255 = 256 Numbers...

Even, how many fingers can you possibly see, is not 10 answers, it is 11... We not using a Decimal system actually, we on a Number11 system... No sorry it is actually Number21... if showing fingers palm forward or backward is added, or if palm forward means "+", we have -10...9, again 21 possibilities...

I rest my case with /az as X# switch...
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

Last edit: by lumberjack.
  • Page:
  • 1