selecting items in multiple listboxes 
Author Message
 selecting items in multiple listboxes

I am writing an application in tcl7.4/tk4.0

I have four listboxes controlled by a single vertical scrollbar,
like this...

   ------------------    ----------------   ----------    ----------  ^
   |                |    |              |   |        |    |        |  |
   |                |    |              |   |        |    |        |  |
   |                |    |              |   |        |    |        |  |
   |                |    |              |   |        |    |        |  |
   |                |    |              |   |        |    |        |  |
   |                |    |              |   |        |    |        |  |
   |                |    |              |   |        |    |        |  |
   ------------------    ----------------   ----------    ----------  v

Does anybody know how to set up the bindings so that selecting an item in
one listbox will automatically select the same index in the other three?  So
that there will always be exactly one item selected in each listbox.

Thanks in advance.

                ///                \\\
               ( ..)              (.. )
------------o00-(_)-00o--------o00-(_)-00o-------
|  Kevin Vlasich, Associate Computer Scientist  |
|  Secure Computing Corp.  Roseville, MN        |

-------------------------------------------------



Mon, 25 May 1998 03:00:00 GMT  
 selecting items in multiple listboxes
: I am writing an application in tcl7.4/tk4.0

: I have four listboxes controlled by a single vertical scrollbar,
: like this...

:    ------------------    ----------------   ----------    ----------  ^
:    |                |    |              |   |        |    |        |  |
:    |                |    |              |   |        |    |        |  |
:    |                |    |              |   |        |    |        |  |
:    |                |    |              |   |        |    |        |  |
:    |                |    |              |   |        |    |        |  |
:    |                |    |              |   |        |    |        |  |
:    |                |    |              |   |        |    |        |  |
:    ------------------    ----------------   ----------    ----------  v

: Does anybody know how to set up the bindings so that selecting an item in
: one listbox will automatically select the same index in the other three?  So
: that there will always be exactly one item selected in each listbox.

Here's one way, perhaps not the most elegant that could be devised:

1. specify "-selectmode single" and "-exportselection 0" for each listbox.

2. Say the listboxes are .l1, .l2, ...  Set up the bindings as follows:

        bind .l1 <Button-1> {
                catch {.l2 selection clear [.l2 curselection]}
          ...   and similarly for all the listboxes other than this one ...

                set index [%W nearest %y]
                .l2 selection set $index
          ...   and similarly for all the listboxes other than this one ...
        }

        ...     and similarly for all the listboxes other than this one ...

-----------------------------------------------------------------------------
        John G. Bay
        Hughes STX, 7701 Greenbelt Rd., Suite 400, Greenbelt, MD  20770

        http://daac.gsfc.nasa.gov/
-----------------------------------------------------------------------------



Mon, 25 May 1998 03:00:00 GMT  
 selecting items in multiple listboxes

Quote:

>Does anybody know how to set up the bindings so that selecting an item in
>one listbox will automatically select the same index in the other three?  So
>that there will always be exactly one item selected in each listbox.

First, make sure that '-exportselection 0' is used for all the listboxes.
Then you can try this:

bind .first <1> {
        foreach lb {.second .third .fourth} {
                $lb select clear 0 end
                $lb select set [%W nearest %y]
        }

Quote:
}

and if you have '-selectmode browse' (as opposed to single):

bind .first <B1-Motion> {
        foreach lb {.second .third .fourth} {
                $lb select clear 0 end
                $lb select set [%W nearest %y]
        }

Quote:
}

Repeat for other listboxes as necessary.
--
     Jeffrey Hobbs                           Office: 541/346-3998

                URL: http://www.cs.uoregon.edu/~jhobbs/


Mon, 25 May 1998 03:00:00 GMT  
 selecting items in multiple listboxes



    >> Does anybody know how to set up the bindings so that selecting
    >> an item in one listbox will automatically select the same index
    >> in the other three?  So that there will always be exactly one
    >> item selected in each listbox.

    Jeffrey> First, make sure that '-exportselection 0' is used for
    Jeffrey> all the listboxes.  Then you can try this:

    Jeffrey> bind .first <1> { foreach lb {.second .third .fourth} {
    Jeffrey> $lb select clear 0 end $lb select set [%W nearest %y] } }

    Jeffrey> and if you have '-selectmode browse' (as opposed to
    Jeffrey> single):

    Jeffrey> bind .first <B1-Motion> { foreach lb {.second .third
    Jeffrey> .fourth} { $lb select clear 0 end $lb select set [%W
    Jeffrey> nearest %y] } }

cool, but this doesn't work if you drag one column down: the other
columns don't follow.
--
Michael Agbaglo              |                          <     >

                             |   (mthode pa?ifique)      | |
pgp: on demand               |                            | |



Sat, 30 May 1998 03:00:00 GMT  
 selecting items in multiple listboxes

Quote:




>    >> Does anybody know how to set up the bindings so that selecting
>    >> an item in one listbox will automatically select the same index
>    >> in the other three?  So that there will always be exactly one

        ... [ solution to above question ] ...

Quote:
>cool, but this doesn't work if you drag one column down: the other
>columns don't follow.

Eh?  Would you care to elaborate?  Do you mean when you select and drag
the selected item, or when attaching a scrollbar?  The former was answered
correctly, but his question didn't say anything about a scrollbar....

--
     Jeffrey Hobbs                           Office: 541/346-3998

                URL: http://www.cs.uoregon.edu/~jhobbs/



Sun, 31 May 1998 03:00:00 GMT  
 selecting items in multiple listboxes


Quote:


>>> cool, but this doesn't work if you drag one column down: the other
>>> columns don't follow.
>I think he's referring to scanning and scrollbars. The solution to

Yes that was what he was referring to, and I wrote some easier code
that I'll repost here that solved the problem:

###########################
proc LBset args {
        foreach lb {.1 .2 .3} {
                eval $lb $args
        }

Quote:
}

proc LBscroll args {
        eval .sy set $args
        LBset yview moveto [lindex $args 0]

Quote:
}

listbox .1 -export no -selectmode browse -yscrollcom LBscroll
listbox .2 -export no -selectmode browse -yscrollcom LBscroll
listbox .3 -export no -selectmode browse -yscrollcom LBscroll
pack .1 .2 .3 -side left -fill both -expand 1

scrollbar .sy -orient v -command "LBset yview"
pack .sy -fill y -side right

for {set i 25} {$i} {incr i -1} {LBset insert end $i}

foreach lb {.1 .2 .3} {
        foreach ev {<ButtonPress-1> <B1-Motion> <ButtonRelease-1>} {
                bind $lb $ev {
                        LBset select clear 0 end
                        LBset select set [%W nearest %y]
                }
        }      

Quote:
}

######################################

It's very easy to extend the number of listboxes.  You can get rid of the
B1-Motion binding if you want to reduce the number of events queued, but the
behavior will be a little different (although the end result is the same).
--
     Jeffrey Hobbs                           Office: 541/346-3998

                URL: http://www.cs.uoregon.edu/~jhobbs/



Tue, 02 Jun 1998 03:00:00 GMT  
 selecting items in multiple listboxes

Quote:






>>>> Does anybody know how to set up the bindings so that selecting
>>>> an item in one listbox will automatically select the same index
>>>> in the other three?  So that there will always be exactly one
[ Munch ]
>> cool, but this doesn't work if you drag one column down: the other
>> columns don't follow.

> Eh?  Would you care to elaborate?  Do you mean when you select and drag
> the selected item, or when attaching a scrollbar?  The former was answered
> correctly, but his question didn't say anything about a scrollbar....

I think he's referring to scanning and scrollbars. The solution to
handling scrollbars has been written by numerous other people before
bot goes something like this

  .1 conf -yscrollcommand {.sb set}
  .2 conf -yscrollcommand {.sb set}
  .3 conf -yscrollcommand {.sb set}
  .4 conf -yscrollcommand {.sb set}
  proc sbcmd {listboxes args} {
      foreach lb $listboxes {eval $lb yview $args}
  }
  .sb conf -command {sbcmd {.1 .2 .3 .4}}

To handle scanning:

  bind .1 <2> {
      foreach lb {.2 .3 .4} {$lb scan mark %x %y}
  }
  bind .1 <B2-Motion> {
      foreach lb {.2 .3 .4} {$lb scan dragto %x %y}
  }

(etc. for other listboxes)

This now almost works, provided you don't let the user put the
keyboard focus on the listboxes, or drag the selection off the bottom
of the listbox - which I suddenly realise is what Michael's question
was actually about!

Hmm. Dealing with those is not exactly easy, but what you'll need to
do is to duplicate the effects of tkListboxAutoScan so that it deals
with multiple windows properly...

  proc dkfListboxAutoScan {args} {
      global tkPriv
      set x $tkPriv(x)
      set y $tkPriv(y)
      set p $tkPriv(listboxPrev)
      set flag 1
      foreach w $args {
          if {$y >= [winfo height $w]} {
              $w yview scroll 1 units
          } elseif {$y < 0} {
              $w yview scroll -1 units
          } elseif {$x >= [winfo width $w]} {
              $w xview scroll 2 units
          } elseif {$x < 0} {
              $w xview scroll -2 units
          } else {
              set flag 0
              break
          }
          set tkPriv(listboxPrev) $p

      }
      if $flag {set tkPriv(afterId) [after 50 dkfListboxAutoScan $args]}
  }
  bind .1 <B1-Leave> {
      set tkPriv(x) %x
      set tkPriv(y) %y
      dkfListboxAutoScan .1 .2 .3 .4
      break
  }

This appears to work! A fuller example is available at:

  http://r8h.cs.man.ac.uk:8000/tcl/linked-listboxes.tcl

Donal.
--
Donal K. Fellows, (at work)          |  Donal K. Fellows, (at home)
Dept. of Computer Science,           |  6, Randall Place, Heaton,
University of Manchester             |  Bradford, BD9 4AE
U.K.      Tel: ++44-161-275-6137     |  U.K.          Tel: ++44-1274-401017

-------------------------------------------------------------------------------
            <http://r8h.cs.man.ac.uk:8000/>  for my home page



Tue, 02 Jun 1998 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. selecting different items from multiple listboxes

2. selecting multiple items in a listbox?

3. multiple listboxes with multiple select

4. Select item in listbox

5. display selected item from listbox to amend data

6. VO: Listbox, display selected item

7. listbox: selected item always highlighted

8. How to Select a Listbox Item???

9. Selected item's index in a listbox ?

10. Selected item's index in a listbox

11. Selecting more items from listbox than shown

12. I would like to select some item in listbox.(tk3.6)

 

 
Powered by phpBB® Forum Software