How to get column value at selected row in hwtk::selectlist ?
Hello,
I have created one selection list box for all the available components in the model with it's name in column 1 and ID in column 2.
My query is to get only component ID when user do the selection.
By using command "selectionget" we get all selected rows when user click on OK button.
So, how to fetch column 2(ID) value in selected row?
I have created below procedure for the same.
proc CompList {} { #Craete New Dialog to display Component List package require postquery set componentList [::hwp::getComponentList -byname 1] set componentIDList [::hwp::getComponentList -id 1] if {[winfo exists .d2]} {destroy .d2} set w2 [hwtk::dialog .d2 -title "Component List"] $w2 hide apply; set recess [$w2 recess] namespace eval ::texample {}; proc ::texample::OnSelect {W S c} { puts [info level 0] } proc ::texample::OnOk {w T} { puts "Selected items are --> [$T selectionget]" # puts "[llength [$T selectionget]]" set cnt [llength [$T selectionget]] } $w unpost } set selList [hwtk::selectlist $recess.sl -stripes 1 -selectmode multiple -selectcommand "::texample::OnSelect %W %S %c" -height 250 -width 500] #set selList [hwtk::selectlist $recess.sl -stripes 1 -selectmode multiple -height 250 -width 500] pack $selList -fill both -expand true; $selList columnadd entities -text Component_Name $selList columnadd id -text ID set cntCompList [llength $componentList] for {set i 0} {$i < $cntCompList } {incr i} { $recess.sl rowadd row$i -values [list entities "[lindex $componentList $i]" id "[lindex $componentIDList $i]"] } $w2 buttonconfigure ok -command "::texample::OnOk $w2 $selList" $w2 post }
Best Answer
-
Hello @Bhavik Sheth ,
here are a couple of suggestions from my colleagues:
- It might be the easiest (probably the most unsophisticated) way to store an array name->id beside the GUI data in a namespace variable.
- The comp id might also be used for the tag, so it can be parsed straight from the selectionget - list:
set cntCompList [llength $componentList]
for {set i 0} {$i < $cntCompList } {incr i} {
$recess.sl rowadd row_ [lindex $componentList $i] -values [list entities "[lindex $componentList $i]" id "[lindex $componentIDList $i]"]
}- From the selection, it can be retrieved this way:
proc ::texample::OnOk {w T} {
puts "Selected items are --> [$T selectionget]"
foreach item [$T selectionget] {
set row [$T rowcget $item -values]
set id [lindex $row end]
}# More logic might be added here , e.g. lsearch "ID". But you have to exclude the case a comp was named "ID"…
puts "$item -> $id"# puts "[llength [$T selectionget]]"
set cnt [llength [$T selectionget]]
}
Hope that helps,
Michael0
Answers
-
Hello @Bhavik Sheth ,
here are a couple of suggestions from my colleagues:
- It might be the easiest (probably the most unsophisticated) way to store an array name->id beside the GUI data in a namespace variable.
- The comp id might also be used for the tag, so it can be parsed straight from the selectionget - list:
set cntCompList [llength $componentList]
for {set i 0} {$i < $cntCompList } {incr i} {
$recess.sl rowadd row_ [lindex $componentList $i] -values [list entities "[lindex $componentList $i]" id "[lindex $componentIDList $i]"]
}- From the selection, it can be retrieved this way:
proc ::texample::OnOk {w T} {
puts "Selected items are --> [$T selectionget]"
foreach item [$T selectionget] {
set row [$T rowcget $item -values]
set id [lindex $row end]
}# More logic might be added here , e.g. lsearch "ID". But you have to exclude the case a comp was named "ID"…
puts "$item -> $id"# puts "[llength [$T selectionget]]"
set cnt [llength [$T selectionget]]
}
Hope that helps,
Michael0 -
Michael Herve_21439 said:
Hello @Bhavik Sheth ,
here are a couple of suggestions from my colleagues:
- It might be the easiest (probably the most unsophisticated) way to store an array name->id beside the GUI data in a namespace variable.
- The comp id might also be used for the tag, so it can be parsed straight from the selectionget - list:
set cntCompList [llength $componentList]
for {set i 0} {$i < $cntCompList } {incr i} {
$recess.sl rowadd row_ [lindex $componentList $i] -values [list entities "[lindex $componentList $i]" id "[lindex $componentIDList $i]"]
}- From the selection, it can be retrieved this way:
proc ::texample::OnOk {w T} {
puts "Selected items are --> [$T selectionget]"
foreach item [$T selectionget] {
set row [$T rowcget $item -values]
set id [lindex $row end]
}# More logic might be added here , e.g. lsearch "ID". But you have to exclude the case a comp was named "ID"…
puts "$item -> $id"# puts "[llength [$T selectionget]]"
set cnt [llength [$T selectionget]]
}
Hope that helps,
MichaelHi @Michael Herve,
Thank you so much for the information.
I used the selection method and made some modifications according to my requirements and it worked.
0