[Gtk-sharp-list] [Mono GTK#] Set Combobox Selected by Value
d.moonfire at mfgames.com
Thu Sep 19 19:56:39 UTC 2013
Basically, you want to set comboBox.Active to the index of your item. If
you happen to know it ahead of time, then go for it. If you can't, then
just loop through the list store to fine the item. I got tired of doing a
lot of these and started putting them into a subclasses ComboBox over in my
MfGames.GtkExt library, but I haven't gotten serious about merging all the
individual branches to make it that useful.
Below is an example of how I did it. This predates my understanding of
LINQ, so it's a bit clumsy. Effectively, I wrote a combo box that takes an
enumeration and displays the values (and returns/sets it via said enum).
// Go through the elements and find the string value
string str = value.ToString();
var store = (ListStore) comboBox.Model;
int index = 0;
foreach (object row in store)
// Check for match
if (str == row.ToString())
comboBox.Active = index;
// Increment the index so we can reference it for the active.
On Thu, Sep 19, 2013 at 10:56 AM, jaymarvels <jacob.spencer80 at googlemail.com
> I don't want to get. I want to set.
> I'll explain again
> I have a liststore...2 columns
> America 10
> Belgium 16
> England 139
> Denmark 166
> This is then bound to the combobox.
> cboNations.Clear ();
> Gtk.CellRendererText text = new CellRendererText
> cboNations.Model = datalist;
> cboNations.PackStart (text, false);
> cboNations.AddAttribute (text, "text", 0);
> I want to set the initial selectedvalue = 139 or something else of my
> In winforms this would be done by setting my combobox datasource to a
> And then doing a combobox selectedvalue = 139;
> View this message in context:
> Sent from the Mono - Gtk# mailing list archive at Nabble.com.
> Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gtk-sharp-list