[Gtk-sharp-list] Set item in ComboBox (novice in GTK#)

Rafael Teixeira monoman at gmail.com
Mon Jun 20 10:18:48 EDT 2005


Oi Paulinho,

cbFiltro.Active = 1; // index (pt_BR: apenas por posição) zero-based.

Property ActiveText has only the 'get' acessor (so it is readonly), so...

In order to select by value you'll need to iterate through the
ListStore searching for it (as it may have been reordered) and
counting up to find it's positional index.

<rant>
Sometimes I miss WinForms Combos' simplicity when dealing with GTK#
versions'  flexibility that normally means larger, and more complex,
code.
</rant>

:)

On 6/18/05, Paulinho <amf.paulo at gmail.com> wrote:
> Hi all,
> 
> I need to set a item in ComboBox, How i do that ?
> 
> In Web i just make this:
> myCombo.SelectedValue = "2" , automatically myCombo show me "Description
> of Option #2"
> sorry i'm novice in GTK# client applications
> 
> 
> my code:
> 
> CellRendererText descricao = new CellRendererText ();
> CellRendererText id          = new CellRendererText ();
> 
> comboBoxStore = new ListStore (typeof (string), typeof (string));
> cbFiltro.Model = comboBoxStore;
> 
> cbFiltro.PackStart (descricao, false);
> 
> cbFiltro.AddAttribute (descricao, "text"  , 0);
> 
> comboBoxStore.AppendValues("Option #1", "1");
> comboBoxStore.AppendValues("Option #2", "2");
> comboBoxStore.AppendValues("Option #3", "3");
> 
> ...
> ...
> 
> string mySelection = "2";
> 
> ???
> 
> 
> How to set the row of ListStore or ComboBox using a value into variable
> "mySelection" ?
> 
> 
> Magalhaes
> 
> /* Sorry my english */
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> 


-- 
Rafael "Monoman" Teixeira
---------------------------------------
I'm trying to become a "Rosh Gadol" before my own eyes. 
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.
It hurts!


More information about the Gtk-sharp-list mailing list