Welcome! Log In Create A New Profile

Advanced

Tri state check box in table not saving third state (on turtorial,express version)

Posted by newbie2 
I am a bit confused,when i run the code below it changes the checkbox to the third state buth it is not saving the third state to database.Do i need to switch the key type checkbox to aray?is there any example that explains handeling the tristate?

(key type checkbox )
status is int
status=TableSelect(TABLE_Time,1,tsRow)
COL_status[status]=-1
HModify(dbclient,status)

i tried the table with direct acces aswell as the table load in memory.no result
Since there is no response i assume its not possible to have a tri state checkbox in a table control and save its state ....it finally happened i encountered a limitation of windev...it had to happen one day tongue sticking out smiley
Hi

It is possible look at the url

[doc.windev.com]

regards

Allard
Not really sure what your code is trying to achieve or from where you are running it.

If from a button then change line 2 to the following and comment out line 3
status = TABLE_Time[TableSelect(TABLE_Time)][1]..Value

This assumes that the checkbox is column 1

If from the table then select the table control, now click on the column itself to select that column only.
F2 will take you to the code for this column.
In the 'On modification' section enter
status = Myself..Value
so ..... ok key hes to be type checkbox array this ;

Check box and databinding
The databinding is available for the Check Box controls under the following conditions:

if the check box has a single option, it must be linked to a simple variable.
if the check box has several options, it must be linked to an array.

If this condition is not respected, a GUI error will be generated.


ofc this only goes so far it does not explain how the array supose to be accesed / or reffered to in the table control.Or how a array in general suppose to be accesed....like how do i define for example the checkbox is in state 1 in array? is it like with a table subscript between the [] or somthing else?yes i know ..... basic knowledge .... as i said just starting .... wd my first attempt at programing so yes you have to asume i know nothing....wd could use a stronger basic turtorial that goes more in depth....
@DerekT
currently i have a table row with 1 checkbox with 2 options either true or false.
ofc it got more complex with as result i need 3 options , however if activate tri checkbox in discription....it does not save the 3th state it just saves state true (1)or false(0) ... with the fille linked.I could add another checkbox to the table buth that looks ugly/silly
Not sure I can really help you as I have never had need to use a 3 state checkbox.

As for the array -- In the analysis a checkbox (or integer) has the option to declare an array for the control to use.
My guess is that this is where you would need to set this up - the link on a databound table would therefore be automatic.
Sadly I have never used this option either so I can offer no advice and as you say the Help is sadly lacking in this area.

Let us know how you get on.
Hi
the help states that the value of the UNDEFINED state is -1.
Therefore, you cannot STORE it's value inside a regular checkbox item in the DB or inside a boolean, which is the same thing, as a boolean only knows 0 and 1 values (unchecked, checked).

So the solution is simply to use a SIGNED INTEGER to store the values (-1,0,1).

Best regards
i tried that before,
when i manualy add -1 value the value changes to 255 .... so its not storing -1
unless i did somthing wrong
Hi Fabrice
To be precise you can store any value in a field declared as a boolean its just that it will not be recognised.
Any number other than zero will be treated as a True condition - in this case -1 but could just as easily be 99.

Storing this in an integer overcomes that issue but how would you display the result in a table column?
My thoughts were that this is why an array is used - although I am still not clear as to how this would be used/displayed from within the table control.

May well have to have a little play later on.



Edited 1 time(s). Last edit at 07/31/2017 02:11PM by DerekT.
Hi again

255 is -1 in an UNSIGNED int. you need a SIGNED one.

as for display, just use the three states checkbox as the 3 states are -1 0 and 1

I don't see where you would need an array for that, it's ONE checkbox, with 3 possible values. And you DON'T want to use a boolean as any value other than zero will be STORED and RETURNED as 1.

Best regards
Just tested and you are correct - using an unsigned INT stores the correct value and the table display shows the correct value.

Also had a look at the Array option ???? - tbh could not make heads nor tails of that.
Hi again

the array option is only there if you have a control with MULTIPLE check boxes (and it doesn't matter if each checkbox is 2 or 3 states), each checkbox value will be saved in one line of the array.

It has therefore nothing to do with the choice between 2 and 3 states. You'll just need an array of boolean OR an array of unsigned ints.

Best regards
I am sorry to bring this up again but it still doesent make head or tails for me......Subtype signed intreger is not availebel in the dropdown list. if i link the key to multifille and link it to a numeric key value stored in the same file with the value /-1/0/1 its still not displaying its state PLEASE be more specifici am new with windev turtorial remember.....

Thanks in Advance

The type you require is '0/9 Numeric' from the Type combo popup.

In the Format section on the right panel click the double down arrow - select the first option of 'Signed 1-byte integer'

The value (-1, 0 1) from the 3 state checkbox will be stored correctly within when the record is saved where the combo is bound (linked) to this field.

Similarly the combo state will correctly display in the when the table is next displayed.

Any further use of the value stored will of course need to through your code.
solved it bye assigning a metatype.
Still i wonder is this the correct way?for doing so ? if i rebuild the table will there not simply be a field that accepts a value from -128 to 127 instead of a checkbox?
i was sure i solved it....
buth it only seems to work with manueel input if i use the code to mark row 3 to state -1 its stil not saving

@DerekT the subtype combox drop down only gives me 1 more option other then checkbox >unsigned intreger

nCc1=TableSelect(TABLE_Time,1,tsRow)
nCc2=TABLE_Time.COL_Onoroff[nCc1]
IF nCc2 = -1 THEN
TABLE_Time.COL_Onoroff[3]=-1
ScreenToFile(newww,TABLE_Time)
END

the intention was whenever any row of the colum onorof is modified. check state if state is -1 if -1 then change all the states of the rows that contain the same group name.

in order to do that i was using the above code to see if it saves 1 change in state before writing more
First I feel obliged to mention that it is pointless for you to come here, ask advice and then argue when it is given.

Using a Metatype is fine but not really necessary - you can achieve what you want from the file definition table.
I guess you are using the v20 Express so from the type dropdown....

Then from the down arrow adjacent to the Format combo....


Yes of course you have defined a field that COULD hold that range - what you are doing is selecting a type that is capable of holding the values you REQUIRE and as has been pointed out a Boolean will not provide that capacity.
Quote
newbie2
i was sure i solved it....
buth it only seems to work with manueel input if i use the code to mark row 3 to state -1 its stil not saving

@DerekT the subtype combox drop down only gives me 1 more option other then checkbox >unsigned intreger

nCc1=TableSelect(TABLE_Time,1,tsRow)
nCc2=TABLE_Time.COL_Onoroff[nCc1]
IF nCc2 = -1 THEN
TABLE_Time.COL_Onoroff[3]=-1
ScreenToFile(newww,TABLE_Time)
END

the intention was whenever any row of the colum onorof is modified. check state if state is -1 if -1 then change all the states of the rows that contain the same group name.

in order to do that i was using the above code to see if it saves 1 change in state before writing more

As I pointed out earlier you need to use the ..Value property and apply that to the control.

Still cannot follow your code but something like the following should work...

In the COLUMN 'whenever modifying' code section
IF MySelf..Value <> -1 THEN
	//Call local procedure
	lpUpdateTriState()
END
PROCEDURE lpUpdateTriState()

// For each row containing the target group name
FOR EACH ROW OF Table1 WHERE Column4 = "Group"
	// Update the TriState checkbox
	IF Column1..Value = -1 THEN
		Column1..Value = 1
	END
END

Finally while I appreciate it is always tempting to get straight down to business I would humbly suggest that you concentrate on the Tutorials.
Also have a look at the WinDEv-US on Google+, lots of webinars avaiable on there.
@Derekt
Before this post i didint know u could link a nummeric with a checkbox control i tought it always had to be same subtype as the key subtype ;like a date key linked to edt field configured as date type.....so when i tried the meta type thing i had no idee why it worked (partialy) and since it only worked in part i tought i still did it wrong....you where explaining another methode i didint quit get until the linked image

Buth i still dont get why the changed state doessent get stored


nCc1=TableSelect(TABLE_Time,1,tsRow)// gets colom row
nCc2=TABLE_Time.COL_Onoroff[nCc1]//gets value of cell
IF nCc2 = -1 THEN //if selected row
TABLE_Time.COL_Onoroff[3]=-1//test to see if i can change and write down the change
ScreenToFile(newww,TABLE_Time)
END

i tested h modify and h add aswell its still refusing to work h add works buth h modify does not.I have been addit for hours now at the point i am now trying work arounds because it still doesent work like it should or at least i cant get it to work (sure it stores when i click on it buth if i cant manipulate the states bye code and save them .its useless to me;a wise men once said : Insanity Is Doing the Same Thing Over and Over Again and Expecting Different Results . I tried evrything i could think of still ......
Quote
newbie2
@Derekt
Before this post i didint know u could link a nummeric with a checkbox control i tought it always had to be same subtype as the key subtype ;like a date key linked to edt field configured as date type.....so when i tried the meta type thing i had no idee why it worked (partialy) and since it only worked in part i tought i still did it wrong....you where explaining another methode i didint quit get until the linked image

Buth i still dont get why the changed state doessent get stored


nCc1=TableSelect(TABLE_Time,1,tsRow)// gets colom row
nCc2=TABLE_Time.COL_Onoroff[nCc1]//gets value of cell
IF nCc2 = -1 THEN //if selected row
TABLE_Time.COL_Onoroff[3]=-1//test to see if i can change and write down the change
ScreenToFile(newww,TABLE_Time)
END

i tested h modify and h add aswell its still refusing to work h add works buth h modify does not.I have been addit for hours now at the point i am now trying work arounds because it still doesent work like it should or at least i cant get it to work (sure it stores when i click on it buth if i cant manipulate the states bye code and save them .its useless to me;a wise men once said : Insanity Is Doing the Same Thing Over and Over Again and Expecting Different Results . I tried evrything i could think of still ......

You really do need to do a bit more research/training IMO

From the Help

ScreenToFile cannot be used to write into the data file: Only the variables of the file items are assigned (which means the variables of the record loaded in memory). To modify the records, you must use HAdd, HModify, HWrite, ...

Check out TableSave() - I suspect this may be your friend

Add this to the code I suggested in the IF condition clause....
// Update the TriState checkbox
	IF Column1..Value = -1 THEN
		Column1..Value = 1
                TableSave(Table1) //The row in question does need to be selected
	END



Edited 1 time(s). Last edit at 08/01/2017 12:46PM by DerekT.
hey DerekT
that was indeed the command i was looking for i think i tried all the others i knew of hadd hmodify, hsave.

just one more small question

PROCEDURE lpUpdateTriState()

// For each row containing the target group name
FOR EACH ROW OF TABLE_Time //cut//
// Update the TriState checkbox
IF TABLE_Time.COL_Onoroff..Value = -1 THEN
TABLE_Time.COL_Onoroff..Value = 1

TableSave(TABLE_Time)
END


END

i realy liked the above code specialy the condition linked to a for each i had to cut the condition since it was flagging red i tried //WHERE Col_group = 'test",and WHERE time.col_group = "test".buth bothed flagged.is there another way i can add the condition in the for each statement?

many thanks for all the help i am happy that i can abort the work around
Ha ha, mislead you there - It seems that WHERE is not applicable to table controls

Not that I think it would be a very efficient way to carry out your requirement as, even were it available, each row would need to have been selected prior to TableSave()

Personally I would use an Update query.

So as before monitor changes to the check box in the COLUMN 'whenever modifying' code section
IF MySelf..Value <> -1 THEN
	//Call local procedure
	lpUpdateTriState()
END
The procedure will now use the query
PROCEDURE lpUpdateTriState()
s_GroupName 	is ANSI string = Table_Test.GroupName..Value  //Name of the group
s_TblSaveInfo 	is ANSI string

s_TblSaveInfo = TableSavePositionAndSelection(Table_Test) //Stores the position of the slected row
HExecuteQuery(UPD_Query1,hQueryDefault+hModifyFile,s_GroupName) //Executes the query - Note use of hModifyFile
TableDisplay(Table_Test) // Refreshes the table display - new values will be visible
TableRestorePositionAndSelection(Table_Test,s_TblSaveInfo) //Returns to the previous position and selects the record
END
HFreeQuery(UPD_Query1) //Release memory
The query can be generated in the Query Generator, the SQL code will look similar to
UPDATE 
   TriBoxTest
SET
   OnOrOff = 1
WHERE 
   TriBoxTest.OnOrOff = -1
   AND TriBoxTest.GroupName = {psGroup}



Edited 2 time(s). Last edit at 08/01/2017 03:43PM by DerekT.
Hi DerekT not there yet;
last couple of days I tried my own script it worked sort off the gui behavior was fine the fille was modified however selecting a row and not clicking on the same row again broke the data fille.

So i decided to try out the Query (this is also my very first query attempt)

After testing the exact code above i failed to get any results on the positive side i didint trigger any fatal error either,....

so i run one of the most simplest update query i could make to get some insights,....
and retried ur code.No luck sadly

Below i will post the stepps of the wizzard and i will also post the adapted code i hope you can tell me where i went wrong

PROCEDURE lpUpdateTriState()
s_GroupName 	is ANSI string = TABLE_Time.COL_Group..Value  //Name of the group
s_TblSaveInfo 	is ANSI string

IF s_TblSaveInfo = TableSavePositionAndSelection(TABLE_Time) THEN

HExecuteQuery(QRY_NoName2,hQueryDefault+hModifyFile,s_GroupName) //Executes the query - Note use of hModifyFile
TableDisplay(TABLE_Time) // Refreshes the table display - new values will be visible
TableRestorePositionAndSelection(TABLE_Time,s_TblSaveInfo) //Returns to the previous position and selects the record
END
HFreeQuery(QRY_NoName2) //Release memory
UPDATE 
//SQL code
TriBoxTest
SET
onoroff = 1
WHERE 
TriBoxTest.onoroff = -1
AND TriBoxTest.GroupName = {psGroup}
//call code whenever col onorof modified
IF MySelf..Value <> -1 THEN
	//Call local procedure
	lpUpdateTriState()
	END
I noticed in the SQL u dont seem to call on the data fille is that because u load it in to memory in the local procedure?(again first step query here)

desired gui behavior:

the steps of the wizzard i took;



in wizard (tab3)
I took a random condition and parameter asuming the SQL code would overwrite whatever i would enter anyway.

my apologies for bringing up this subject again buth it felt important to finaly approach the query beast.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: