Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk Q : How to highlight selected items in two listboxes same time? 1

Status
Not open for further replies.

nikhil079

Technical User
Oct 24, 2010
4
0
0
US
Hi,
I am new to Tcl/Tk programming and I must be missing something very simple here. I am trying to create two listboxes and the entries in second box is controlled by the item selected in first list box. I managed to get this working by bind <<ListboxSelect>> commands. Issue is, when I select the items in second listbox (X Y Z or P Q R ) listbox1 item is not highlighted any more (blue background). Is it possible to highlight the selected items in both boxes same time? (for example "1" in listbox 1 and "Y" in listbox2 ).


Here is my simple code and I am using Tcl8.4.

Thanks in advance for all your help.


###
set list1val "1 2"
scrollbar .s1 -command ".list1 yview"
listbox .list1 -selectmode "single" -yscroll ".s1 set" -listvariable list1val

scrollbar .s2 -command ".list2 yview"
listbox .list2 -selectmode "single" -yscroll ".s2 set" -listvariable list2val


bind .list1 <<ListboxSelect>> { setlist_second [.list1 curselection] }

grid .list1 -row 0 -column 0 -sticky news
grid .s1 -row 0 -column 1 -sticky news
grid .list2 -row 0 -column 2 -sticky news
grid .s2 -row 0 -column 3 -sticky news



proc setlist_second { SelIndex } {

if { $SelIndex == 0} {
variable list2val "X Y Z"
} else {
variable list2val "P Q R"
}

}

###

--Nikhil
 
The hard part is that when you depress the mouse button the selection index returned by "curselection" is the previous selection, until the button is released. Therefore you need to instantiate the listbox in "-selectmode single" so that the <ButtonRelease-1> event is captured.

Code:
() 26 % pack [listbox .lb1 -listvariable lstA -selectmode single] -side left
() 27 % pack [listbox .lb2 -listvariable lstB -selectmode single] -side left
() 28 % bind .lb1 <ButtonRelease-1> {.lb2 selection set [.lb1 curselection]; focus .lb2}

_________________
Bob Rashkin
 
Thanks Bob !! I will try your suggestions as soon as I get a chance. Thanks again !!

Regards
Nikhil
 
nikhil, I was wondering, did it help whay Bob replied to you?

maybe this is what you are looking for (in addition to your script):

.list2 config -exportselection 0
 
Hi,
Finally I got a chance to test this. I tried thakoda's suggestion and that gave the results I needed..Thanks for your help :)

Rgds
Nikhil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top