How to uncheck checkbox in datagrid without click on this

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

How to uncheck checkbox in datagrid without click on this

Post by QuangNgo » Fri Mar 23, 2012 4:53 am

Dear guys,

I am working project of printing Id Card for students. Here are the following lists I have to do:
-Load students from CSV into datagrid (I did it)
-Display checkbox with default status is true (in case for user want to uncheck students. I dit it)
-Printing job will automatically run and each students ID card is printed successfully, data of checkbox will be set false to announce that record has been done
and I can make it change value in datagrid from true into false.However, in visibility the checkbox still checked although data has been changed in datagrid

So Here my code

Code: Select all

on mouseUp
   //send "printKeys" to group "DataGrid 1"
    put the dgNumberOfRecords of grp "DataGrid 1" into tStudentCount
     if tStudentCount > 0 then
     put the dgData of grp "DataGrid 1" into ListData
     put the dgIndexes of grp "DataGrid 1" into theLines  
     
    repeat for each item tline in theLines
      put ListData[tline]["StudentID"] into tStudentId
      put ListData[tline]["StudentCard"] into tStudentCard
      put ListData[tline]["Status"] into tStatus
      //do print card ......
      // do register card to database .......
      --Here I want to update status after printing successfully
      --turn tStatus mode true into false to announce users the progressing
       put not tStatus into theCheckedValue      
      dispatch "SetDataOfLine" to group "DataGrid 1" with tline, "Status", theCheckedValue -- it works fine how ever checkbox still checked
  
   end repeat
    end if
end mouseUp
Could you guys please help me how to uncheck the checkbox ?

I am so appreciated

Regards,
Quang

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to uncheck checkbox in datagrid without click on thi

Post by Klaus » Fri Mar 23, 2012 2:56 pm

Hi Quang,

mabe you need to refresh each row after updating? Try this:

Code: Select all

on mouseUp
    put the dgNumberOfRecords of grp "DataGrid 1" into tStudentCount

    ## Avoid unneccessary long IF... THEN... clauses ;-)
     if tStudentCount < 1 then
        exit mouseup
     end if

     put the dgData of grp "DataGrid 1" into ListData
     put the dgIndexes of grp "DataGrid 1" into theLines  

     ## INDEX <> Line!
     
    repeat for each item tline in theLines
      put ListData[tline]["StudentID"] into tStudentId
      put ListData[tline]["StudentCard"] into tStudentCard
      put ListData[tline]["Status"] into tStatus
      put not tStatus into theCheckedValue  
    
      ## I think this should be SetDataOfINDEX!!!!
      dispatch "SetDataOfINDEX" to group "DataGrid 1" with tline, "Status", theCheckedValue 
      REFRESHINDEX tLine
   end repeat
 end mouseUp
Best

Klaus

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Re: How to uncheck checkbox in datagrid without click on thi

Post by QuangNgo » Fri Mar 23, 2012 3:47 pm

Hi Klaus,

Thanks I'll try to do it and hope it works as i thought

Regards,
Quang

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to uncheck checkbox in datagrid without click on thi

Post by Klaus » Fri Mar 23, 2012 4:00 pm

Hi Quang,
QuangNgo wrote:... and hope it works as i thought
so do I! :D


Best

Klaus

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Re: How to uncheck checkbox in datagrid without click on thi

Post by QuangNgo » Mon Mar 26, 2012 6:32 am

Hi Klaus,

I try and it doesn't work.

Code: Select all

REFRESHINDEX tLine
can't fine the handler so I try

Code: Select all

dispatch "REFRESHINDEX" to group "DataGrid 1" with tline
and no difference

Could you guys give me some advice for that?

Best regards,
Quang

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: How to uncheck checkbox in datagrid without click on thi

Post by Zryip TheSlug » Wed Mar 28, 2012 9:17 pm

QuangNgo wrote:Hi Klaus,

I try and it doesn't work.

Code: Select all

REFRESHINDEX tLine
can't fine the handler so I try

Code: Select all

dispatch "REFRESHINDEX" to group "DataGrid 1" with tline
and no difference

Could you guys give me some advice for that?

Best regards,
Quang
Hi Quang,

As you are changing the data for column "status" of all the rows in the datagrid, you could use the "RefreshList" command at the end of your script:

Code: Select all

dispatch "RefreshList" to group "DataGrid 1"
By adding this line, the final script would be:

Code: Select all

on mouseUp
   //send "printKeys" to group "DataGrid 1"
    put the dgNumberOfRecords of grp "DataGrid 1" into tStudentCount
     if tStudentCount > 0 then
     put the dgData of grp "DataGrid 1" into ListData
     put the dgIndexes of grp "DataGrid 1" into theLines  
     
    repeat for each item tline in theLines
      put ListData[tline]["StudentID"] into tStudentId
      put ListData[tline]["StudentCard"] into tStudentCard
      put ListData[tline]["Status"] into tStatus
      //do print card ......
      // do register card to database .......
      --Here I want to update status after printing successfully
      --turn tStatus mode true into false to announce users the progressing
       put not tStatus into theCheckedValue
   end repeat
    end if
   dispatch "RefreshList" to group "DataGrid 1"
end mouseUp
The mouseUp handler changes the state of the data for each rows in the column "status". However, the checkbox will be updated only if you have the right code in your column behavior for column "status". Maybe the error is located here.

For checking / unchecking a checkbox in a datagrid column depending of its content, you should have something equivalent to this fillInData handler, in the column behavior script:

Code: Select all

on FillInData pData
   if (pData is "true") then
      set the hilited of button "myCheckBox" of me to true
   else
      set the hilited of button "myCheckBox" of me to false
   end if

   //or shorter: set the hilited of button "myCheckBox" of me to pData
end FillInData
Where "myCheckBox" is the name of the checkbox in your template for column "status"


Best regards,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Re: How to uncheck checkbox in datagrid without click on thi

Post by QuangNgo » Tue Apr 03, 2012 2:20 am

Hi Zryip TheSlug,

Thanks a lot for your help , so appreciated ^^

Regards,
Quang

Post Reply