Page 1 of 1
setting checkbox in data grid to disabled
Posted: Sun Oct 14, 2012 11:05 am
by japino
I have a data grid with a list of checkboxes. I have another checkbox outside the data grid and depending of the state of that checkbox (let's call this checkbox the lonely checkbox) one of the checkboxes in the data grid should be disabled (greyed out). I've found that it's easy to select or unselect a checkbox in the datagrid by clicking the lonely checkbox using this script (2 is the line item in the data grid):
Code: Select all
on mouseUp
if the hilite of me then
dispatch "SetDataOfLine" to group "DataGrid" with 2, "checked", true
else
dispatch "SetDataOfLine" to group "DataGrid" with 2, "checked", false
end if
dispatch "RefreshList" to group "DataGrid-trans"
end mouseUp
I was hoping that I could do something somilar with the "disabled" property, such as:
Code: Select all
on mouseUp
if the hilite of me then
dispatch "SetDataOfLine" to group "DataGrid" with 2, "disabled", false
else
dispatch "SetDataOfLine" to group "DataGrid" with 2, "disabled", true
end if
dispatch "RefreshList" to group "DataGrid-trans"
end mouseUp
But this does not work. The checkbox is always enabled. What am I doing wrong?
Re: setting checkbox in data grid to disabled
Posted: Sun Oct 14, 2012 1:51 pm
by Klaus
Hi Japino,
well, you are "just" setting a value in the data of the datagrid (dgData):
-> dgdata_array[2]["disabled"]["true/false"]
but this does not affect the look and beaviour of your objects inside of the datagrid!
You need of course to set the en-/disabled of that button explicitely like:
Code: Select all
on mouseUp
if the hilite of me then
dispatch "SetDataOfLine" to group "DataGrid" with 2, "disabled", false
enable me
###***
else
dispatch "SetDataOfLine" to group "DataGrid" with 2, "disabled", true
disable me
end if
dispatch "RefreshList" to group "DataGrid-trans"
end mouseUp
***But once a button is disabled, clicking on it will NOT enable it again, so you need to do tis via script!
I hope I understood correctly what you are after
Best
Klaus
Re: setting checkbox in data grid to disabled
Posted: Sun Oct 14, 2012 6:40 pm
by japino
Hi Klaus,
Thanks very much for your reply! Just a few things to note:
- I'm trying to check the look and behavior of a checkbox in a data grid by clicking a checkbox that is not part of the data grid
- This works fine when I use the "checked" property. The checkbox in the datagrid changes immediately when I click the checkbox that is not part of the data grid.
- But when I use the "disabled" property, nothing happens. I would expect to see the checkbox in the data grid greyed out when I click the checkbox that is not part of the data grid.
Hope this explains a bit more.
(By the way, my example code has an error. The final dispatch command is sent to group "DataGrid-trans". This should be just "DataGrid". This is just an error in this forum post. The correct code (with just DataGrid) does not do what I want it to do, as I described above).
If you could have another look at this and may be could figure out what is wrong, I'd be very happy!
Thanks,
Japino
Re: setting checkbox in data grid to disabled
Posted: Sun Oct 14, 2012 6:52 pm
by Klaus
H iJapino,
ah, sorry, I thought the button with the script was actually the checkbox in the datagrid!
Well, I think you need to add something to the "on fillinData" handler in the datagrids behaviour like:
Code: Select all
on fillinData tArray
set the disabled of btn "the checkbox we are talking about" of me to (tArray["disabled"] = true)
## more of your stuff here
end fillinData
This handler will always be called when you "setdataofline" or the complete data with "set the dgData..."
Hint for saving some typing (I am the GODFATHER of lazyness

)
Code: Select all
on mouseUp
dispatch "SetDataOfLine" to group "DataGrid" with 2, "checked", the hilite of me
## will always evaluate the correct value :-)
dispatch "RefreshList" to group "DataGrid"
end mouseUp
As you can see in both of my scripts, using BOOLEAN values with sense can save a LOT of typing!
Ah, and welcome to the forum!
Best
Klaus
Re: setting checkbox in data grid to disabled
Posted: Mon Oct 15, 2012 7:46 am
by japino
Hi Klaus,
Thanks again and thanks for the welcome
I tried this out, but the result when I click the non-datagrid checkbox so that a checkmark appears, a checkmark appears in the checkbox in the data grid as well. And when I click the non-datagrid checkbox so that the checkmark disappears, the checkmark disappears in the checkbox in the data grid as well.
But I want the checkbox in the datagrid to be
greyed out when I remove the checkmark from the non-datagrid checkbox.
I had hoped that changing the "checked" property from your second script to "disabled" might do the trick (as follows), but alas...
Code: Select all
dispatch "SetDataOfLine" to group "DataGrid" with 2, "disabled", the hilite of me
If you have any other ideas what might be wrong, that would be great. In the past I worked with HyperTalk and I see a lot of similarities but obviously this datagrid stuff is all a bit new and overwhelming...
Re: setting checkbox in data grid to disabled
Posted: Mon Oct 15, 2012 11:15 am
by Klaus
Hi Japino,
hmm, did you add the "fillinData" stuff?
Replacing "checked" with "disabled" will work with the "mouseup" example,
but not without the appropriate "fillinData" command!
Best
Klaus
Re: setting checkbox in data grid to disabled
Posted: Mon Oct 15, 2012 11:46 am
by japino
Hi again Klaus,
Wow, thanks! It now works. There was indeed something wrong in my FillInData handler. It now looks like this, and it works, I'm happy!
Code: Select all
on FillInData pDataArray
set the label of button "Check" of me to pDataArray["label"]
set the hilited of button "Check" of me to pDataArray["checked"]
set the disabled of btn "Check" of me to (pDataArray["disabled"] = true)
end FillInData
Thank you so much!
japino
Re: setting checkbox in data grid to disabled
Posted: Mon Oct 15, 2012 11:51 am
by Klaus
YEAH!
