Re: Setting an iter from an ID value
- From: Carl Nygard <cjnygard fast net>
- To: Daniel Kasak <dkasak nusconsulting com au>
- Cc: gtk-perl mailing list <gtk-perl-list gnome org>
- Subject: Re: Setting an iter from an ID value
- Date: Wed, 21 Jul 2004 23:17:18 -0400
I do some similar contortions in C++ code. The only seeming difference
is that I maintain the option vector separately from the widget, so I
can just scan through the options and figure the matching index, then
use
Gtk::Menu* menu = _optionMenu->get_menu();
menu->set_active(_active);
menu->activate_item(menu->items()[_active], true);
On Wed, 2004-07-21 at 22:25, Daniel Kasak wrote:
Hi all.
I have some code which I'm not completely happy with.
I have a combo box with a Gtk2::ListStore model, which contains 2
fields: an ID field and a string field.
Here's how I'm currently selecting the iter:
my $iter = $widget->get_model->get_iter_first;
$widget->get_child->set_text(""); # In case no match is found for some
reason
while ($iter) {
if ($id_from_database eq $widget->get_model->get($iter, 0)) {
$widget->set_active_iter($iter);
last;
}
$iter = $widget->get_model->iter_next($iter);
}
This works, but doesn't seem like a very economical way of doing things.
I've thought about getting the string field from the database and using
$widget->get_child->set_text($string) but that also seems kinda dodgy,
and won't work if there are duplicate strings ( not that there should
be, but anyway ... )
Is there a better way of doing this?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]