Next: Container Widgets Up: The TixSelect Widget Previous: Accessing the Value

### Specifying Complex Selection Rules

If you want to have more complex selection rules for the TixSelect widget, you can use the `-validatecmd` option. This option works the same as the `-validatecmd` option of the TixControl widget which we discusses in section 1.2: it specifies a command to be called every time the user attempts to change the selection inside a TixSelect widget.

In the example program 1-14, the procedure `TwoMax` will be called every time the user tries to change the selection of the `.fruits` widget. `TwoMax` limits the maximum number of fruits that the user to choose to be 2 by always truncating the value of the TixSelect widget to have no more than two items. If you run this program, you will find out that you can never select a third fruit after you have select two fruits.

`tixSelect .fruits -label "Fruits: " -radio false -validatecmd TwoMax
.fruits add apple -text Apple -width 6
.fruits add orange -text Orange -width 6
.fruits add banana -text Banana -width 6
pack .fruits
proc TwoMax {value} {
if {[llength $value] $>$ 2} {
return [lrange $value 0 1]
} else {
return $value
}
}`

(Figure 1-14) Specifying More Complex Selection Rules