Jump to content
Jouher

Provide right click option to hwtk component table cell

Recommended Posts

From HM14, a menu is attached to table cell as default, but to show it, use option -cellmenucommand

You have to provide a tcl proc (not menu name)

Purpose of that proc is to customize the cell menu (already created as default, you don't need to create it)

That proc accepts %M as argument to refer cell menu name, then you can use it to add or remove menu commands suitable with each cell type

 

Example

hwtk::table .myTable -cellmenucommand {p_PrepareMenu %M %C}

.myTable columncreate name -text name

.myTable columncreate id -text id

.myTable rowinsert end row1 -values {name comp1 id 1001}

.myTable rowinsert end row2 -values {name comp2 id 3000}

 

proc p_PrepareMenu {mnu column} {

   $mnu delete 0 end

   switch -- $column {

         name {

              $mnu add command -label Rename

         }

         id {

              $mnu add command -label Renumber

         }

    }

}

 

 

 

 

 

 

As I see, when creating hwtk table, option -menu will attach a menu with event "right click" on header of column 0

 

 

When creating a column, option -headermenu will attach a menu with event "right click" on header of that column.

 

 

 

 

vipin likes this

Share this post


Link to post
Share on other sites

Because it's a hwtk menu, sub commands "delete" and "add" are changed to methods "clear" and "item"

proc p_PrepareMenu {mnu column} {

   $mnu clear

   switch -- $column {

         name {

              $mnu item Rename -caption Rename -command {puts "write a proc to rename comp"}

         }

         id {

              $mnu item Renumber -caption Renumber -command {puts "write a proc to renumber comp"}

         }

    }

}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...