GRIDPLUS2 - Selecting a Tablelist Row, Tree Node or Calendar Date | ![]() |
||||||
|
Selecting a Tablelist Row, Tree Node or Calendar Date |
GRIDPLUS provides the gpselect command to select a Tablelist row, Tree node or Calendar date.
For Tablelist and Tree the selected row/node is highlighted, the value of the "null" array item set and, if "-action single" is specified for the Tablelist/Tree, the action procedure is invoked. For calendar the value of the associated variable is set. The Calendar will also "navigate" to the month/year of the specified date and the day will be highlighted.
Syntax |
As from GRIDPLUS release 2.11 a modified (backward compatible) gpselect syntax has been introduced so as to allow a more logical parameter order when selecting a Tablelist row. I have also introduced a -row option which has the same effect as -index as I feel this makes code more readable. I am now recommending use of the new "|" option instead of "--". This has the effect of turning off option processing, reversing the column and match parameters (If a column has been specified) -and- acting as a separator to improve code readability.
The syntax is partially free-form. The following rules apply:-
For backward compatibility the default parameter order is:-
The "|" option (Introduced in GRIDPLUS 2.11) reverses the order of the column and match parameters (If a column is specified) when selecting a Tablelist row. This is the order used by gpdelete and gpupdate such that, for a Tablelist, the parameter order is:-
For a match where no column is specified:-
For a match where a column is specified:-
Otherwise:-
Note: For the purposes of documentation/examples the following is used:-
gpselect item ?options? ?column? match|row|date
Examples:
To select row "3" of ".mytable" any of the following are valid:-
gpselect .mytable -row 3 gpselect -row .mytable 3 gpselect .mytable 3 -row
Some examples also using the "-focus" option:-
gpselect .mytable -focus -row 3 gpselect -focus -row .mytable 3 gpselect .mytable 3 -row -focus gpselect .mytable -row 3 -focus gpselect .mytable -row -focus 3
When using gpselect to match by column content where the content to match begins with "-" the "|" option can be used to turn off option processing.
Examples:
To select the row in ".mytable" where the first column matches "-ABC123" the following are valid:-
gpselect .mytable | "-ABC123" gpselect .mytable -focus | "-ABC123" gpselect -focus .mytable | "-ABC123"
Note: For Tablelist selection by match it is recommended that the "|" option always be used.
Selecting a Tablelist Row |
A Tablelist row can be selected in the following ways:-
Note: For -max and -min the sort order for the specified column is used define the order.
Syntax:-
gpselect item ?-focus? | ?column? match
gpselect item ?-focus? -row row
gpselect item ?-focus? -max column
gpselect item ?-focus? -min column
gpselect item ?-focus? -first
gpselect item ?-focus? -last
gpselect item -save ?column?
gpselect item ?-focus? -restore
For Example:
gpselect .mytable | "ABC123"
...Will select the row in ".mytable" where the content of the first column is "ABC123".
gpselect .mytable | reference "ABC123"
...Will select the row in ".mytable" where the content of the column with name "reference" is "ABC123".
gpselect .mytable -focus | reference "ABC123"
...Will select the row in ".mytable" where the content of the column with name "reference" is "ABC123" and give focus to the Tablelist.
gpselect .mytable -row 3
...Will select the fourth row in ".mytable".
gpselect .mytable -focus -row 3
...Will select the fourth row in ".mytable" and give focus to the Tablelist.
gpselect .mytable -max id
...Will select the row in ".mytable" which has the highest value for the column with name "id".
gpselect .mytable -last
...Will select the last row in ".mytable".
gpselect .mytable -save
...Will save the index for the currently selected row in ".mytable" - (Restore will select the row which has the "saved" index).
gpselect .mytable -save reference
...Will save the value of the column named "reference" for the currently selected row in ".mytable" - (Restore will select the row where the column named "reference" matches the "saved" value).
gpselect .mytable -restore
...Will select the previously "saved" row in ".mytable".
Selecting a Tree Node |
A Tree node is selcted by matching (exactly) the path name of a node.
Syntax:-
gpselect item node
For Example:
gpselect .mytree "/Dir1/Dir2/File1"
...Will select the node in ".mytree" where the node path is "/Dir1/Dir2/File1".
Selecting a Calendar Date |
A Calendar date is selected by specifying the required date. The date must be in the format specified by -dateformat.
Syntax:-
gpselect item date
gpselect -selectonly item {}
For Example:
gpselect .mycal 08/25/2009...Will set/select August 25th 2009.
To clear the selection and the Calendar value specify null as the date...
For Example:
gpselect .mycal {}
Using the -selectonly option it is possible to clear the selection without altering the value (See calendar example).
For Example:
gpselect -selectonly .mycal {}
Example |
This example has the following functionality:-
Window:
If the "File4" node in the Tree is selected using a single-click the following is displayed:-
...Then selecting the "Second Row" radiobutton...
...Then selecting the "File6/Seventh Row" row in the Tablelist using a double-click...
Source Code:
#======================================================# # Procedure invoked by single-click on ".mytree" node. # #======================================================# proc mytree {} { global {} gpselect .mytable | $(.mytree) } #======================================================# # Procedure invoked by double-click on ".mytable" row. # #======================================================# proc mytable {} { global {} gpselect .mytree [lindex $(.mytable) 0] gpset .mybutton [lindex $(.mytable) 1] } #================================================# # Procedure invoked when radion button selected. # #================================================# proc mybutton {} { global {} gpselect .mytable | description $(.mybutton) } #==========================================================# # Create tree, tablelist, radiobuttons and display window. # #==========================================================# gridplus tree .mytree -action single -height 8 -open 1 -width 230 gridplus tablelist .mytable -action double -height 8 { 0 "Node" 0 "Description" } gridplus radiobutton .mybutton -rcmd mybutton { {.1 "First Row" "-First Row"} {.2 "Second Row" "-Second Row"} {.3 "Third Row" "-Third Row"} {.4 "Fourth Row" "-Fourth Row"} {.5 "Fifth Row" "-Fifth Row"} {.6 "Sixth Row" "-Sixth Row"} {.7 "Seventh Row" "-Seventh Row"} } gridplus layout .main -wtitle "Example: gpselect" { .mytree .mytable .mybutton } pack .main gpset .mytree { {/Dir1 +} {/Dir1/Dir2 +} /Dir1/Dir2/File2 /Dir1/Dir2/File3 /Dir1/File4 /Dir1/File5 /File6 } gpset .mytable { {/Dir1 {First Row}} {/Dir1/Dir2 {Second Row}} {/Dir1/Dir2/File2 {Third Row}} {/Dir1/Dir2/File3 {Fourth Row}} {/Dir1/File4 {Fifth Row}} {/Dir1/File5 {Sixth Row}} {/File6 {Seventh Row}} }
Comments:
proc mytree {} { global {} gpselect .mytable | $(.mytree) }
"gpselect .mytable | $(.mytree)" selects the row in ".mytable" where the first column in the row matches the value of the selected ".mytree" node.
Note: By default the first column is matched.
proc mytable {} { global {} gpselect .mytree [lindex $(.mytable) 0] gpset .mybutton [lindex $(.mytable) 1] }
"gpselect .mytree [lindex $(.mytable) 0]" selects the the node in ".mytree" where the path of the node matches the first column of the selected ".mytable" row.
"gpset .mybutton [lindex $(.mytable) 1]" selects the ".mybutton" Radiobutton which has the selection value which matches the second column of the selected ".mytable" row.
proc mybutton {} { global {} gpselect .mytable | description $(.mybutton) }
"gpselect .mytable | description $(.mybutton)" selects the row in ".mytable" where the column named "description" in the row matches the value of the selected ".mybutton" Radiobutton.
gridplus tree .mytree -action single -height 8 -open 1 -width 230
gridplus tablelist .mytable -action double -height 8 { 0 "Node" 0 "Description" }
gridplus radiobutton .mybutton -rcmd mybutton { {.1 "First Row" "-First Row"} {.2 "Second Row" "-Second Row"} {.3 "Third Row" "-Third Row"} {.4 "Fourth Row" "-Fourth Row"} {.5 "Fifth Row" "-Fifth Row"} {.6 "Sixth Row" "-Sixth Row"} {.7 "Seventh Row" "-Seventh Row"} }
gridplus layout .main -wtitle "Example: gpselect" { .mytree .mytable .mybutton } pack .main
gpset .mytree { {/Dir1 +} {/Dir1/Dir2 +} /Dir1/Dir2/File2 /Dir1/Dir2/File3 /Dir1/File4 /Dir1/File5 /File6 } gpset .mytable { {/Dir1 {First Row}} {/Dir1/Dir2 {Second Row}} {/Dir1/Dir2/File2 {Third Row}} {/Dir1/Dir2/File3 {Fourth Row}} {/Dir1/File4 {Fifth Row}} {/Dir1/File5 {Sixth Row}} {/File6 {Seventh Row}} }