Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selected value from mono Gtk.ComboBox?

Tags:

combobox

mono

gtk

How do I get the selected value (either the string, or an int reference) from a Gtk.ComboBox in mono? All I can find is stuff about using iterators. Why isn't there a function to simply fetch the value (or is there)?

like image 671
David Mulder Avatar asked Sep 29 '11 17:09

David Mulder


2 Answers

For (int) index you can use:

comboBox.Active;

and for text:

comboBox.ActiveText;
like image 189
konrad.kruczynski Avatar answered Oct 20 '22 00:10

konrad.kruczynski


to get the selected value in a GTK+ combo box I used:

 TreeIter tree;
 comboBox.GetActiveIter(out tree);
 TreeModel = comboBox.Model ();
 String selectedText = (String) comboBox.Model.GetValue (tree, 0);

"comboBox" is the GTK combo box. I hope this will help.

like image 44
Emanuele Avatar answered Oct 19 '22 23:10

Emanuele