Datagrid Check boxes

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Datagrid Check boxes

Post by bsouthuk » Thu Feb 03, 2011 12:44 pm

Hi All

I'm trying to to work out how to code a button that if pressed will check the check box of each row that is displayed in my datagrid. If i press another button then the check box of each row in the datagrid needs to uncheck.

Your help is most appreciated!

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid Check boxes

Post by bsouthuk » Thu Feb 03, 2011 2:11 pm

easy...

Code: Select all

    repeat with i = 1 to the number of buttons of group "Campaign"
set the highlight of button i of group "Campaign" to true
   end repeat

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Datagrid Check boxes

Post by bangkok » Thu Feb 03, 2011 2:12 pm

Here is a small sample, with check boxes.
Attachments
TESTDATAGRID.zip
(7.62 KiB) Downloaded 325 times

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid Check boxes

Post by bsouthuk » Thu Feb 03, 2011 3:50 pm

Great thanks you for that. I was hoping the datagrid example would show how to filter the records with checked check boxes. I have around 400 records in my datagrid and want it to display just the records that have checked check boxes.

Is this easy enough?

I have looked at every single datagrid lesson and none of them explain how to do this...

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Datagrid Check boxes

Post by bangkok » Thu Feb 03, 2011 4:47 pm

bsouthuk wrote:Great thanks you for that. I was hoping the datagrid example would show how to filter the records with checked check boxes. I have around 400 records in my datagrid and want it to display just the records that have checked check boxes..
In this case, it's different.

-1 put the content of your grid in a var

-2 analyse each line, with a repeat loop, look for a flag (in my example, the column "status"), and build a new var with the lines that contain the flag

-3 put the new var into your grid. et voila !


So it could be :
1-
put the dgText of group "myDataGrid" into theContent

2-
set itemdelimiter to tab
put empty into theFilteredContent
repeat with i = 1 to the number of lines of theContent
if item 2 of line i of theContent = "1" then put line i of theContent & CR after theFilteredContent ---- here the column "status" is the item number 2
end repeat

3-
put false into pFirstLineContainsHeaders
set the dgText [ pFirstLineContainsHeaders ] of group "myDataGrid" to theFilteredContent

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Re: Datagrid Check boxes

Post by Janschenkel » Thu Feb 03, 2011 5:32 pm

A while back I wrote up a blog post on filtering datagrids which you might want to check out.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid Check boxes

Post by bsouthuk » Thu Feb 03, 2011 5:36 pm

Thats great but how do I set the text to '1' if the check box is checked?

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: Datagrid Check boxes

Post by trevordevore » Fri Feb 04, 2011 3:40 pm

I've added a lesson to the Data Grid manual that shows how to work with checkboxes in a data grid. At the end of the lesson there is an example of checking/unchecking every row. Let me know if this helps clear things up.

http://lessons.runrev.com/spaces/lesson ... Data-Grid-
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid Check boxes

Post by bsouthuk » Fri Feb 04, 2011 4:27 pm

Thank you so much for this, its exactly what I need, however my datagrid has to be a table but the datadrid breaks if I change it from Form. Why is this?

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: Datagrid Check boxes

Post by trevordevore » Fri Feb 04, 2011 4:32 pm

When you switch to "table" you won't have columns named "label" and "checked" so the data in the dgData array that is assigned to the data grid has no columns to display the values.

Try adding two colums (or renaming any existing ones) to "label" and "checked". Then both buttons will work again, although you won't have a checkbox displayed. You would need to go back and customize the "checked" column to contain a checkbox.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid Check boxes

Post by bsouthuk » Fri Feb 04, 2011 5:07 pm

Thanks Trevor. Am getting close here but the datagrid is returning the following error message:

OBJECT Value is not a boolean (true or false) for line: set the hilited of button "Check" of me to pDataArray["checked"]

This has only happened when I have changed from Form to Table.

Also, I need a a button that allows me to select all or deselects all check boxes in the datagrid. Sometimes there can be 100's of records in the datagrid and when the check box is checked it needs to display as true and false when not selected.

Could you possibly supply me with this code please?

Thank you

Daniel

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: Datagrid Check boxes

Post by trevordevore » Fri Feb 04, 2011 5:15 pm

Regarding the error - Did you do anything else after changing from Form to Table? If I just switch to table in the object inspector and click the buttons I don't see any error message.

Did you customize one of the columns? If so then the the value passed to FillInData is NOT an array so pDataArray["checked"] would be empty. When working with tables the parameter passed to FillInData is the value of the column being populated. In this case you would just set the hilite of button "Check" of me to pData. Take a look at the lesson on customizing table columns:

http://lessons.runrev.com/spaces/lesson ... s-Columns-

You will find the code for selecting/deselecting the checkboxes in the lesson I provided. It will work the same for forms or tables. As long as you set the hilite state of the checkbox in FillInData based on a column value then the code will work.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Post Reply