# Event-Issue with TreeCtrl with "TR\_MULTIPLE"

**URL:** <https://www.ruby-forum.com/t/event-issue-with-treectrl-with-tr-multiple/163174>\
**Category:** wxRuby\
**Created:** [March 17, 2009, 11:07pm UTC](https://www.ruby-forum.com/t/event-issue-with-treectrl-with-tr-multiple/163174 "2009-03-17T23:07:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [March 17, 2009, 11:07pm UTC](https://www.ruby-forum.com/t/event-issue-with-treectrl-with-tr-multiple/163174/1 "2009-03-17T23:07:03Z")

</div>

Hi,

I’ve yet another issue with my favourite toolkit.

When I’m adding a TreeCtrl that has the TR\_MULTIPLE style set, the event  
“evt\_tree\_sel\_changed” most oftenly gets fired multiple times (whereas a  
TreeCtrl with single selection only fires once - as expected). The  
exception is the automatic root-selection at program startup and when  
I’m widening or narrowing the selected nodes holding ctrl and using the  
cursor keys.

See the attachment or below for an example how to reproduce this.  
I’m working on WinXP, wxRuby 2.0.0, ruby 1.8.6

require ‘wx’  
include Wx

class MyFrame \< Frame  
def initialize  
super nil, -1, “Tree: select-event error?”

```
@tree = TreeCtrl.new(self, -1, :style => TR_MULTIPLE)
@root = @tree.add_root 'root', 0

['one', 'two', 'three', 'four'].each do |i| add i end
@tree.expand @root

@num_sels = 0

evt_tree_sel_changed(@tree) do |e|
  @num_sels += 1
  puts "sel event #{@num_sels}"
end

```

end

def add item  
node = @tree.insert\_item @root, 0, item, 1  
child = @tree.insert\_item node, 0, “child”, 2  
@tree.insert\_item child, 0, “grand-child”, 2  
@tree.expand node  
@tree.expand child  
end  
end

class MyApp \< App  
def on\_init  
f = MyFrame.new  
f.show  
end  
end

MyApp.new.main\_loop

Thanks in advance for any hint,  
Christian.
