This is the question that I will answer myself:

In tcl/tk, how to bind <Double-1>  to tablelist and get the selected row contents ?

The < Double-1 > represents the mouse button-1 double click in the tcl/tk command bind . Button-1 is by default the left mouse button for right-handed people.

I am writing this question just for indexing on search engines. It took me long to figure how it's done.

1

There are 1 best solutions below

0
superlinux On

Let's imagine that you have a list of students. Here you put them in the table list .students_tablelist . Read the code below to understand how it's done.

 package require tablelist    
 
 proc display_selected_student { } {
   
      #fill the body of this proc with the what should happen on double click 
      # we are going to give an example here on how to extract the field in the selected row
        set selected_tablelist_row_contents [.students_tablelist get [.students_tablelist curselection] ]
        set student_id [ lindex   $selected_tablelist_row_contents 0 ]
        set student_name [ lindex $selected_tablelist_row_contents 1 ]
        set student_enrollment_date [ lindex $selected_tablelist_row_contents 2 ]

        #printing the three variables above on terminal/command line prompt screen
        # and in a message box
        puts "Student ID: $student_id , Student Name: $student_name , Enrollemnt Date: $student_enrollment_date"
        tk_messageBox -message "Student ID: $student_id , Student Name: $student_name , Enrollemnt Date: $student_enrollment_date"
}
 

 #define the tablelist called ".students_tablelist" 
 tablelist::tablelist .students_tablelist -columntitles { "Student ID"  "Student Name"  "Enrollment Date" } -stretch all -background white -height 15 -width 100 

 #some data about a list of students 
 set student_table_data {
       { 1 john 1-march-2024}
       {2 mary 2-march-2024}
       { 3 solo 3-march-2024} 
    }


#fill the tablelist with the three rows from $student_table_data
foreach row $student_table_data {   
  .students_tablelist insert end $row
}

#this bind command is how you attach a mouse double click event to the tablelist
bind [ .students_tablelist bodytag] <Double-1>   {
    #call the proc above and run it.
    display_selected_student
}
   #display the tablelist .students_table on the main root window
   grid .students_table -row 0 -column 0