You are not logged in.
Pages: 1
This is driving me nuts !
I am trying to figure out how you get the text from the selection of a combobox (note: not combo entry box)
I have populated the combobox Ok by attaching a liststore to it :
// set up model for combo box
m_refComboModel = Gtk::ListStore::create(m_Combo);
viewComboBox->set_model(m_refComboModel);
viewComboBox->pack_start(m_Combo.view_col);
// Set the 3 default values for the combobox
Gtk::TreeModel::Row row = *(m_refComboModel->append());
row[m_Combo.view_col] = "item 1";
row = *(m_refComboModel->append());
row[m_Combo.view_col] = "item 2";
row = *(m_refComboModel->append());
row[m_Combo.view_col] = "item 3";
I have a signal that is generated if the user make a selection from the combobox in the following function :
//---------------------------------------------
// User has selcted new positon in combo box
//--------------------------------------------
void window1::on_viewComboBox_changed()
{
// get the current selection from the combobox
// to do ........................................................
TreeModel::iterator i = viewComboBox->get_active();
}
tried variuos ways but I can not figure out how to get the item selected.
get_active always returns 1.
Can anybody show me the light (preferably with an example)
Offline
i think you want to use:
Gtk::TreeIter it;
viewComboBox->get_active_iter(it);
Offline
No the combobox does not have a get_active_iter method - so this just gives a compile error.
but thanks for the quick reply
Offline
ah... it's been a while since I touched the gtkmm stuff... I actually thing the *iter methods were before gtkmm was known as gtkmm... I'm not really sure
Offline
PyGTK says:
gtk.ComboBox.get_active_text
def get_active_text()
Returns : The currently active text.
Note
This method is available in PyGTK 2.6 and above.
The get_active_text() method returns the currently active string or None if no entry is selected. Note that you can only use this function with combo boxes constructed with the gtk.combo_box_new_text() function.
so either wait for GTKmm to wrap the GTK 2.6 or switch to Python or maybe use
get_active_row_number ?
but does on_viewComboBox_changed() get executed?
if you get the iter, do you get the value in the iter?
Good Luck, if you want write a small executable code to reproduce your pb so we can help better
Offline
Ahhh I can use the specialized class ComboBoxText then I can use the get_active_text method. You can't seem to insert his widget using Glade so I did not realize this at first.
Offline
Pages: 1