GRIDPLUS2 - Selecting a Tablelist Row, Tree Node or Calendar Date (Depreciated Version)
Home Reference Manpage Examples Download License Contact

Selecting a Tablelist Row, Tree Node or Calendar Date

NOTE: This method is now depreciated - Please refer to the Latest Documentation.

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.10 a modified (backward compatible) gpselect syntax has been introduced to bring it into line with other GRIDPLUS commands.

The syntax is now partially free-form. The following rules apply:-

Note: For the purposes of documentation/examples the following is used:-

gpselect ?options? item match|index|date ?column?

Examples:

To select row "3" of ".mytable" any of the following are valid:-

gpselect -index .mytable 3
gpselect .mytable 3 -index
gpselect .mytable -index 3

Some examples also using the "-focus" option:-

gpselect -focus -index .mytable 3
gpselect .mytable 3 -index -focus
gpselect .mytable -index 3 -focus
gpselect .mytable -index -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 -focus .mytable -- "-ABC123"
gpselect .mytable -focus -- "-ABC123"

Selecting a Tablelist Row

A tablelist row can be selected in two ways:-

Syntax:-

gpselect ?-focus? item ?--? match ?column?
gpselect ?-focus? ?-index? item index

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".

gpselect -focus .mytable "ABC123" 2

...Will select the row in ".mytable" where the content of the third column is "ABC123" and give focus to the tablelist.

gpselect -index .mytable 3

...Will select the fourth row in ".mytable".

gpselect -index .mytable end

...Will select the last row in ".mytable".

gpselect -focus -index .mytable 3

...Will select the fourth row in ".mytable" and give focus to the tablelist.

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".

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:-

  • When a tree node is selected (single-click) the corresponding tablelist row is selected.
  • When a tablelist row is selected (double-click) the corresponding tree node and radiobutton are selected.
  • When a radiobutton is selected the corresponding tablelist row is selected.

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)
}

Creates a procedure called "mytree" which is invoked by a single-click on a node in the ".mytree" tree.

"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]
}

Creates a procedure called "mytable" which is invoked by a double-click on a row in the ".mytable" tablelist.

"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
}

Creates a procedure called "mybutton" which is invoked when a ".mybutton" radiobutton is selected.

"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

Creates a GRIDPLUS tree called ".mytree". The "-action single" option causes a procedure called "mytree" to be invoked when a node is selected using a single-click.
gridplus tablelist .mytable -action double -height 8 {
   0 "Node"
   0 "Description"
}

Creates a GRIDPLUS tablelist called ".mytable". The "-action double" option causes a procedure called "mytable" to be invoked when a row is selected using a double-click.
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"}
}

Creates a GRIDPLUS radiobutton grid called ".mybutton". The "-rcmd mybutton" option causes a procedure called "mybutton" to be invoked when a radiobutton is selected.
gridplus layout .main -wtitle "Example: gpselect" {
   .mytree
   .mytable
   .mybutton
}

pack .main

Creates and displayes a GRIDPLUS layout called ".main" to arrange the tree, tablelist and radiobuttons one above the other.
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}}
}

Populates ".mytree" and ".mytable" with suitable example data.


Copyright © 2013 Adrian Davis.