# TreeCtrl event help

**URL:** <https://www.ruby-forum.com/t/treectrl-event-help/226266>\
**Category:** wxRuby\
**Created:** [February 20, 2012, 5:05am UTC](https://www.ruby-forum.com/t/treectrl-event-help/226266 "2012-02-20T05:05:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andresdsn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@andresdsn](https://www.ruby-forum.com/u/andresdsn)\
**Post date:** [February 20, 2012, 5:05am UTC](https://www.ruby-forum.com/t/treectrl-event-help/226266/1 "2012-02-20T05:05:39Z")

</div>

hey could someone hel me cus I need to get the label for the selected  
item when expanded but when I use the method evt\_tree\_expaded or  
evt\_tree\_expanding it gives me nil like this:

require ‘wx’  
include Wx  
class MyFrame \< Frame  
def initialize  
super(nil,  
:title =\> “prueba”  
)  
@my\_panel = Panel.new(self)  
@my\_label = StaticText.new(@my\_panel,  
:label =\> “MY”,  
:pos =\> [150, 25],  
:size =\> Wx::DEFAULT\_SIZE)  
@my\_textbox = TextCtrl.new(@my\_panel,  
:name =\> “Default Textbox Value”,  
:pos =\> [20, 20])  
@my\_combo = Wx::ComboBox.new(@my\_panel,  
:name =\> “Default Combo Text”,  
:pos =\> [150, 25],  
:choices =\> [‘Item 1’, ‘Item 2’, ‘Item 3’])  
@my\_button = Button.new(@my\_panel, -1, ‘My Button Text’)  
evt\_button @my\_button, :my\_button\_click  
@my\_panel\_sizer = BoxSizer.new(VERTICAL)  
@my\_panel.set\_sizer(@my\_panel\_sizer)  
@my\_panel\_sizer.add(@my\_label, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_textbox, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_combo, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_button, 0, GROW|ALL, 2)  
show()  
end  
def get\_name(eve)  
@id = eve.get\_item  
@text = @tree.get\_item\_text(@id)  
end  
def my\_button\_click(event)  
@dir\_dialog = Dialog.new(nil,  
:size =\> [400, 400])  
@dir\_view = GenericDirCtrl.new(@dir\_dialog,  
:size =\> [390, 340],  
:dir =\> ENV[“HOME”] )  
@dir\_vsizer = VBoxSizer.new  
@dir\_dialog.set\_sizer(@dir\_vsizer)  
@accept = Button.new(@dir\_dialog,  
:label =\> “Accept”,  
:id =\> ID\_OK)  
@tree = @dir\_view.get\_tree\_ctrl  
evt\_tree\_item\_expanded @tree, :get\_name  
@dir\_vsizer.add(@dir\_view, 0, 2)  
@dir\_vsizer.add(@accept, 0, GROW|ALL, 2)  
case @dir\_dialog.show\_modal  
when ID\_OK  
@tree\_select = @tree.get\_selection()  
@tree\_text = @tree.get\_item\_text(@tree\_select)  
#poner cheque por si no es carpeta mandarlo de regreso  
#llamarlo usando el metodo dir\_button\_click  
@my\_label.label = @text  
@dir\_text.clear  
@error\_dialog = Dialog.new(nil,  
:title =\> “Error”,  
:size =\> [500, 100])  
@error\_text = StaticText.new(@error\_dialog,  
:label =\> “You must chose a folder”,  
:style =\> ALIGN\_CENTRE)  
@ok\_error = Button.new(@error\_dialog,  
:id =\> ID\_OK)  
@error\_size = VBoxSizer.new  
@error\_dialog.set\_sizer(@error\_size)  
@error\_size.add(@error\_text, 0, GROW|ALL, 2)  
@error\_size.add(@ok\_error, 0, GROW|ALL, 2)  
case @error\_dialog.show\_modal  
when ID\_OK  
end  
end  
end  
end  
end  
class MyApp \< App  
def on\_init  
MyFrame.new  
end  
end  
MyApp.new.main\_loop()

Is this the way its done or there is a better way please help
