Databinding Checkbox and Boolean null

Posts   
 
    
JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 15-Aug-2012 10:04:05   

Hello,

I use LLBLgen V3.5

I have a question regarding databinding of checkbox, boolean values and null values.

I have bound an entity to a bindingsource on a winform. On this form als a few members are bound to a check box. Let's say one of my Entity boolean members has the name "CleanTimeStampFromFileName"

Default the member is bound to the CheckState property of a checkbox, but you also have the Checked property where you can bind to.

Question 1: In case of LLBL Gen generated entity and my CleanTimeStampFromFileName member of a boolean type, which of the above to use?

Question 2: When i create a NEW entity, and bind this to the screen, then the boolean properties of the entity are "Null" (via the entity.Fiels[index].CurrentValue you can see it is NULL but -> when i get the boolean member say entity.CleanTimeStampFromFileName -> i see "False". when inserting i get and SQL exception, column can not be null. where do i fix this behavior -> if the user didn't checked it then it is default "false". What's your advice..

Question 3: I use injection for validation, and in my ValidateEntity function i check on the entity.CleanTimeStampFromFileName and not the entity.Fiels[index].CurrentValue so no validation message was thrown, what is the best practice on these kind of validation checks? which on to use.

i mean i can fix this issues, but i find it hard to digest what the "best practices" are for this situations. Hope you guys can shine a light on this one simple_smile

Regards, Joey

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Aug-2012 22:16:43   

Question 1: In case of LLBL Gen generated entity and my CleanTimeStampFromFileName member of a boolean type, which of the above to use?

Use the field not the indexed current value.

Question 2: When i create a NEW entity, and bind this to the screen, then the boolean properties of the entity are "Null" (via the entity.Fiels[index].CurrentValue you can see it is NULL but -> when i get the boolean member say entity.CleanTimeStampFromFileName -> i see "False". when inserting i get and SQL exception, column can not be null. where do i fix this behavior -> if the user didn't checked it then it is default "false". What's your advice..

If the field doesn't allow null, then the default value that pears in code is the default value for theta .NET type. If the field's value isn't changed nothing would be inserted into the database. And so you'd get the database exception, which you can avoid if you have a default value set for that column in the database.