Page 1 of 2
Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 10:50 am
by CAsba
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.
Re: Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 2:52 pm
by dunbarx
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
Re: Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 2:54 pm
by dunbarx
CAsba
Know that columns in a dataGrid are default named "Col 1, Col 2, Col 3,..."
Craig
Re: Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 3:06 pm
by dunbarx
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
Re: Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 3:13 pm
by dunbarx
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
Re: Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 4:09 pm
by Klaus
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
Re: Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 5:35 pm
by dunbarx
Klaus.
Sort of what I said.
But I could neither hide nor show a DG column with the test handler I published.
Craig
Re: Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 8:18 pm
by Klaus
Hi Craig,
dunbarx wrote: ↑Wed Jun 28, 2023 5:35 pm
Klaus.
Sort of what I said.
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
Re: Set all columns in a datagrid to "visible"
Posted: Wed Jun 28, 2023 8:38 pm
by dunbarx
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.
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
Re: Set all columns in a datagrid to "visible"
Posted: Thu Jun 29, 2023 1:54 am
by stam
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...
Re: Set all columns in a datagrid to "visible"
Posted: Thu Jun 29, 2023 12:23 pm
by CAsba
Thanks everyone for all the info, and to you Klaus, for the definitive answer.
Re: Set all columns in a datagrid to "visible"
Posted: Fri Jun 30, 2023 4:41 pm
by bobcole
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
Re: Set all columns in a datagrid to "visible"
Posted: Fri Jun 30, 2023 5:40 pm
by CAsba
Thanks BobCole, I'll take a look !
Re: Set all columns in a datagrid to "visible"
Posted: Thu Nov 07, 2024 2:23 pm
by CAsba
Hi,
In my table datagrid, 36 columns, 54 lines, I have a problem. I have a on/off button script that effects the showing of all columns, then showing just 4 columns. This performs OK for two selections, all - just 4, but the third call for all columns to be shown results in an error message.
Similarly, clicking on a line with more than 4 populated columns shows all the populated columns; clicking another line with just 4 populated columns also shows the 4 columns; clicking a third time on a line with more than 4 populated columns also results in an error.
As a developer, I can get rid of the error by using the reset facility, but I wouldn't want the reset facility to be available to the user - a red button "Click here to clear datagrid errors" would be unacceptable.
Can anyone throw any light on this ?
Re: Set all columns in a datagrid to "visible"
Posted: Thu Nov 07, 2024 3:49 pm
by Klaus
Hi CAsba,
CAsba wrote: ↑Thu Nov 07, 2024 2:23 pm
... but the third call for all columns to be shown results in an error message...
what does the error dialog tell you?
And what did you script for the on/off button?
Best
Klaus