Setting an iter from an ID value



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?

--
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
Title: CanIt Vote for ID 71778

The following links have been inserted by the NUS Consulting internal spam filter and are for NUS Consulting staff only
Spam
Not spam
Forget previous vote


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