Re: Gtk2::ComboBox - setting value by string?



John M. Burian wrote:
It doesn't fix the 'bug', such as it is, but a technique I use is to, as 
I'm adding values to the ListStore, create a hash that maps the strings 
back to the indicies of the ListStore, then add a reference to that hash 
to the ComboBox object.

$list = Gtk2::ListStore->new ("Glib::String");
map {
  $list->set ($iter = $list->append, 0, $_);
  $$href{$_} = $list->get_string_from_iter ($iter);
} (qw/Option1 Option2 Option3/);
$combobox = Gtk2::ComboBox->new_with_model ($list);
$combobox->{hash} = $href;

Then later, to set the value of the combobox using the string:

$combobox->set_active ($combobox->{hash}{'Option1'});
  

Are you allowed to do this? I've read in a number of places that it's
dangerous to keep iters around for any length of time ... ie that they
are only valid immediately.

-- 
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
website: http://www.nusconsulting.com.au



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]