# How to get ComboBox strings?

**URL:** <https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703>\
**Category:** Ruby-Gnome 2\
**Created:** [March 13, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703 "2007-03-13T17:57:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladimir\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@Vladimir\_F](https://www.ruby-forum.com/u/Vladimir_F)\
**Post date:** [March 13, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703/1 "2007-03-13T17:57:01Z")

</div>

Hi all!

I have following problem : I’m using gtk2 and I want to write an  
application wich, after start loads strings which should be in some  
ComboBoxEntry from external file and in the end saves them back to same  
file (similar behaviour as URL history in browser).

Problem is that I don’t know how to get list of strings stored in  
ComboBox (Gtk::ComboBoxEntry.new(true)). According to reference manual,  
there are onle Gtk::ComboBox#append\_text, Gtk::ComboBox#insert\_text,  
Gtk::ComboBox#prepend\_text, Gtk::ComboBox#remove\_text and  
Gtk::ComboBox#active\_text methods supported.

So I miss some kind of array-like mechanism for access to strings  
stored in  
ComboBox list. Could anybody help me please ?

Thanks,

V.

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Vladimir\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@Vladimir\_F](https://www.ruby-forum.com/u/Vladimir_F)\
**Post date:** [March 13, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703/2 "2007-03-13T18:11:03Z")

</div>

On Tue, Mar 13, 2007 at 05:55:56PM +0100, Vladimir F. wrote:

> Gtk::ComboBox#prepend\_text, Gtk::ComboBox#remove\_text and  
> Gtk::ComboBox#active\_text methods supported.

Unfortunately, there’s no API for that when using Gtk::ComboBox in the  
“convenience mode” with just strings. You’ll have to iterate over the  
underlying Gtk::TreeModel to get all the strings:

list = []  
combo\_box.model.each { |model, path, iter| list \<\< model.get\_value(iter,  
0) }

(Should work in theory, haven’t tested here)

-pete

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Vladimir\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@Vladimir\_F](https://www.ruby-forum.com/u/Vladimir_F)\
**Post date:** [March 13, 2007, 6:15pm UTC](https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703/3 "2007-03-13T18:15:04Z")

</div>

I haven’t used the text only version, but you can use a ListStore for  
the model like so:

@combo\_list = Gtk::ListStore.new(String)

[‘one’,‘two’,‘three’].each do |a|  
iter = @combo\_list.append  
iter[0] = a  
end

@combo\_box = Gtk::ComboBox.new(@combo\_list)

Curtis

Vladimir F. wrote:

> Gtk::ComboBox#prepend\_text, Gtk::ComboBox#remove\_text and  
> Take Surveys. Earn Cash. Influence the Future of IT  
> Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share your  
> opinions on IT & business topics through brief surveys-and earn cash  
> [http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
> 
> * * *
> 
> ruby-gnome2-devel-en mailing list  
> removed\_email\_address@domain.invalid  
> [ruby-gnome2-devel-en List Signup and Options](https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en)

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Vladimir\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@Vladimir\_F](https://www.ruby-forum.com/u/Vladimir_F)\
**Post date:** [March 13, 2007, 8:56pm UTC](https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703/4 "2007-03-13T20:56:38Z")

</div>

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Vladimir\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@Vladimir\_F](https://www.ruby-forum.com/u/Vladimir_F)\
**Post date:** [March 13, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703/5 "2007-03-13T21:06:40Z")

</div>

Just beware that Gtk::Combo is deprecated.

From the docs:

“As of GTK+ 2.4, Gtk::Combo  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACombo](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACombo) has been  
deprecated in favor of Gtk::ComboBox  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AComboBox](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AComboBox).”

on this page:  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACombo](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACombo)

Dobai-Pataky BÃ¡lint wrote:

> > @combo\_list = Gtk::ListStore.new(String)  
> > Vladimir F. wrote:
> > 
> > > ## there are onle Gtk::ComboBox#append\_text, Gtk::ComboBox#insert\_text,
> > 
> > [ruby-gnome2-devel-en List Signup and Options](https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en)  
> > removed\_email\_address@domain.invalid  
> > [ruby-gnome2-devel-en List Signup and Options](https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en)

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Vladimir\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@Vladimir\_F](https://www.ruby-forum.com/u/Vladimir_F)\
**Post date:** [March 15, 2007, 12:54am UTC](https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703/6 "2007-03-15T00:54:42Z")

</div>

Hi all!

I tryied Peter J.'s code and it works perfectly. I also tryied  
Curtis  
Summers’s code, but I was not able to force the code to work ☹ (truth  
is  
that I did not play with it too much, because previuous way worked).  
Anyway,  
I have at least one way how to do job done! Thank you very much guys!  
🙂

V.

I FEEL HAPPY 🙂

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Vladimir\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@Vladimir\_F](https://www.ruby-forum.com/u/Vladimir_F)\
**Post date:** [March 13, 2007, 8:59pm UTC](https://www.ruby-forum.com/t/how-to-get-combobox-strings/88703/7 "2007-03-13T20:59:38Z")

</div>

On Tue, Mar 13, 2007 at 09:50:52PM +0200, Dobai-Pataky B??lint wrote:

> how about trying the Gtk::Combo, and not the Gtk::ComboBox?  
> Gtk::Combo is for text only and does not use a model, as far as i  
> understood.

Gtk::Combo is an old widget, and really not suggested for new code.  
Gtk::ComboBox is the way of the future! (:

-pete

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
