| GRIDPLUS2 - Selecting a Tablelist Row or Tree Node | ![]() |
||||||
|
| Selecting a Tablelist Row or Tree Node |
GRIDPLUS provides the gpselect command to select a Tablelist row or Tree node.
In both cases 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.
| Selecting a Tablelist Row |
A Tablelist row is selected by matching (extactly) the contents of a specified column. By default the first column (Column "0") is used.
Syntax:-
gpselect item match ?column?
For Example:
gpselect .mytable "ABC123"
...Will select the row in ".mytable" where the content of the first column is "ABC123".
gpselect .mytable "ABC123" 2
...Will select the row in ".mytable" where the content of the third column is "ABC123".
| Selecting a Tree Node |
A Tree node is selcted by matching (exactly) the path name of a node.
Syntax:-
gpselect item match
For Example:
gpselect .mytree "/Dir1/Dir2/File1"
...Will select the node in ".mytree" where the node path is "/Dir1/Dir2/File1".
| 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 $(.mybutton) 1
}
#==========================================================#
# 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 $(.mybutton) 1
}
"gpselect .mytable $(.mybutton) 1" selects the row in ".mytable" where the second column 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}}
}