Set all columns in a datagrid to "visible"

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
CAsba
Posts: 389
Joined: Fri Sep 30, 2022 12:11 pm

Set all columns in a datagrid to "visible"

Post by CAsba » Wed Jun 28, 2023 10:50 am

Hi, how can I script to make all the columns in a datagrid table visible ? I've read the lessons, but I'm sorry to say I'm afraid it makes no sense to me.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set all columns in a datagrid to "visible"

Post by dunbarx » Wed Jun 28, 2023 2:52 pm

CAsba.

There is a property, the "dgColumnIsVisible[yourColumnHere]" that can be set to "true"

I do not know if there is a blanket property, but you can always loop through all columns.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set all columns in a datagrid to "visible"

Post by dunbarx » Wed Jun 28, 2023 2:54 pm

CAsba

Know that columns in a dataGrid are default named "Col 1, Col 2, Col 3,..."

Craig
Last edited by dunbarx on Wed Jun 28, 2023 8:39 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set all columns in a datagrid to "visible"

Post by dunbarx » Wed Jun 28, 2023 3:06 pm

All.

I never used that property, so decided to try it out. I made a new plain vanilla DG with a few columns and rows. But when I

Code: Select all

 answer the dgColumnIsVisible["Col2"] of grp 1
 set the dgColumnIsVisible["Col2"] of grp 1 to "false"
Invoking the first line I get empty.
Invoking the second line does nothing.

???

MAC OS 13.4 LC 9.6.9

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set all columns in a datagrid to "visible"

Post by dunbarx » Wed Jun 28, 2023 3:13 pm

Here is another wrinkle that I do not understand. In a new DG with data in a few columns and rows, If I:

Code: Select all

on mouseup
   answer the dgText of grp 1
   answer the dgColumnIsVisible["XXX"] of grp 1
end mouseup
After line 1 I get the contents of the DG.
After line 2, which references a non-existent column, I get empty instead of an error.

I do not understand DG's.

Craig

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Set all columns in a datagrid to "visible"

Post by Klaus » Wed Jun 28, 2023 4:09 pm

Hi CAsba,

do this:

Code: Select all

...
## Get a list of all columns in your DG
put the dgprops["columns"] of grp "your dg here..." into tColumns

## Now loop through this list and do the right thing with dgColumnisvisible:
repeat for each line tColumn in tColumns
    set the dgColumnIsVisible[tColumn] of grp "your dg here..." to TRUE
end repeat
...
Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set all columns in a datagrid to "visible"

Post by dunbarx » Wed Jun 28, 2023 5:35 pm

Klaus.

Sort of what I said. :wink:

But I could neither hide nor show a DG column with the test handler I published.

Craig

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Set all columns in a datagrid to "visible"

Post by Klaus » Wed Jun 28, 2023 8:18 pm

Hi Craig,
dunbarx wrote:
Wed Jun 28, 2023 5:35 pm
Klaus.

Sort of what I said. :wink:
But I could neither hide nor show a DG column with the test handler I published.

Craig
my example handler above works as exspected, it shows hidden columns!
I always test my stuff before posting. ;-)

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set all columns in a datagrid to "visible"

Post by dunbarx » Wed Jun 28, 2023 8:38 pm

Klaus.

AHA. There is a typo in the dictionary, which has as its example:

Code: Select all

put the dgColumnIsVisible["col1"] of group "Data Grid"
when even I know that the default column names are "Col 1, Col 2, etc". That is, a space between, say, "Col" and "2".

I just copied the example, and used it in more than one place. :oops:

But that is the easy part. Why then did LC not throw an error when I tried to manipulate column "Col1" (no space) which does not exist?

Craig

stam
Posts: 2777
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Set all columns in a datagrid to "visible"

Post by stam » Thu Jun 29, 2023 1:54 am

what is already said is a good way.

Another way, especially if you have groups of columns you want to show/hide, is to simply set the dgProps["columns"] of the datagrid, where "columns" is a return-delimited list.
No matter what is in the dgData of the datagrid, it will only display the columns that are in dgProps["columns"]. If a column corresponds to a subway in dgData (as this is numerically indexed, all columns are subways to a numeric key), then it will be shown.

Just be aware that while the data will persist because it's in the dgData, the column widths may not do, so if not standard width you'd need to set that as well.
It's great for showing sets of columns with a single command...

CAsba
Posts: 389
Joined: Fri Sep 30, 2022 12:11 pm

Re: Set all columns in a datagrid to "visible"

Post by CAsba » Thu Jun 29, 2023 12:23 pm

Thanks everyone for all the info, and to you Klaus, for the definitive answer.

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 138
Joined: Tue Feb 23, 2010 10:53 pm
Location: Saint Louis, Missouri USA

Re: Set all columns in a datagrid to "visible"

Post by bobcole » Fri Jun 30, 2023 4:41 pm

I have a Data Grid with six columns. Investigating the properties of the Data Grid, I came across this:

Code: Select all

on mouseUp pButtonNumber
   set the dgProp["column visibility"] of group "Data Grid" to "true,true,true,true,true,true"
end mouseUp
According to the dictionary this allows all the columns to be set to visible at once. This is what the OP requested.
Beware: the dictionary says the command should be a line-delimited list of columns but I found that a comma-delimited list works.

You can use 'false' instead of 'true' anywhere in the command to selectively set the visibility of a column.

Try it, I think you will like it.
Bob

CAsba
Posts: 389
Joined: Fri Sep 30, 2022 12:11 pm

Re: Set all columns in a datagrid to "visible"

Post by CAsba » Fri Jun 30, 2023 5:40 pm

Thanks BobCole, I'll take a look !

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”