Page 1 of 1

Datagrid Check boxes

Posted: Thu Feb 03, 2011 12:44 pm
by bsouthuk
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!

Re: Datagrid Check boxes

Posted: Thu Feb 03, 2011 2:11 pm
by bsouthuk
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

Re: Datagrid Check boxes

Posted: Thu Feb 03, 2011 2:12 pm
by bangkok
Here is a small sample, with check boxes.

Re: Datagrid Check boxes

Posted: Thu Feb 03, 2011 3:50 pm
by bsouthuk
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...

Re: Datagrid Check boxes

Posted: Thu Feb 03, 2011 4:47 pm
by bangkok
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

Re: Datagrid Check boxes

Posted: Thu Feb 03, 2011 5:32 pm
by Janschenkel
A while back I wrote up a blog post on filtering datagrids which you might want to check out.

HTH,

Jan Schenkel.

Re: Datagrid Check boxes

Posted: Thu Feb 03, 2011 5:36 pm
by bsouthuk
Thats great but how do I set the text to '1' if the check box is checked?

Re: Datagrid Check boxes

Posted: Fri Feb 04, 2011 3:40 pm
by trevordevore
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-

Re: Datagrid Check boxes

Posted: Fri Feb 04, 2011 4:27 pm
by bsouthuk
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?

Re: Datagrid Check boxes

Posted: Fri Feb 04, 2011 4:32 pm
by trevordevore
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.

Re: Datagrid Check boxes

Posted: Fri Feb 04, 2011 5:07 pm
by bsouthuk
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

Re: Datagrid Check boxes

Posted: Fri Feb 04, 2011 5:15 pm
by trevordevore
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.