$tree_view->set_search_equal_func(sub { # reset to the main tree store, containing all the hosts $tree_view->set_model($tree_store); my ($_tree_store, $path, $pattern, $iter) = @_; return unless length($pattern) > 2; my %results; $_tree_store->foreach(sub { my ($model, $path, $iter) = @_ ; my $host = $model->get($iter, 0); my $ip = $model->get($iter, 1); if($host =~ /$pattern/){ # print "Found $host for $pattern\n"; $results{$host} = $ip; } # return 0, so that the function always iterates through # the entire tree store return 0 }); # build the new tree store and display in the tree view if(scalar keys %results > 0){ my $new_treestore = create_treestore(\%results); $tree_view->set_model($new_treestore); # $tree_view->set_cursor(0); $tree_view->set_search_column(0); # my $iter = $new_treestore->get_first_iter(); my $path = $new_treestore->get_path( $new_treestore->get_iter_first() ); $tree_view->set_cursor($path); undef $path; #get the Gtk2::TreeSelection of $tree_view my $treeselection = $tree_view->get_selection; #set its initial mode $treeselection->set_mode('single'); } }, undef);