3

I have a ComboBoxEntry:

my $com_entry = Gtk2::ComboBoxEntry->new($model, 0);

and I need to delete the user entry from a ComboBoxEntry (to set an empty value). The method $com_entry->set_active_iter(undef); of ComboBox doesn't work. Any ideas? Thanks for a response.

happy coder
  • 1,517
  • 1
  • 14
  • 29
edem
  • 3,222
  • 3
  • 19
  • 45

2 Answers2

1

According to what is meant by "delete the user entry":

  1. If you just want to set the entry text to be empty:

    $com_entry->child->set_text ("");
    
  2. If you want to select nothing:

    $com_entry->set_active (-1);
    
  3. If you want to remove a selected item from the popup menu:

    my $model = $com_entry->get_model;
    my $iter = $com_entry->get_active_iter;
    defined $iter and $model->remove ( $iter );
    

Hope it is helping.

ophidion
  • 223
  • 1
  • 7
0

I'm kind of guessing here, I use GTK+ in my MonoDevelop projects, and I toy around with PERL when I need something quick and dirty. What about something like: $com_entry->append_text("");?

You might get some other ideas from: here:

happy coder
  • 1,517
  • 1
  • 14
  • 29
  • Did you check the link for ideas? I got the impression that GTK2 PERL documentation is a little thin on the ground, maybe look into GTK2 documentation and give it the mental spin so that it works in PERL. – happy coder Jan 01 '13 at 17:59
  • Yes, I did. I read some other sites and doc for Gtk2::ComboBoxEntry but there are only methods which just insert or append text into a ComboBox's list of values. But for me is needed to clear what user typed in Entry field of ComboBoxEntry. – edem Jan 01 '13 at 18:35
  • Oh, ok, I've just edited your post to make it more clear. Maybe someone will be able to answer what you really want. – happy coder Jan 02 '13 at 05:07
  • What about: gtk.ComboBox.remove_text()? Which would be: $com_entry->remove_text(); ? – happy coder Jan 02 '13 at 05:10
  • $combo_box->remove_text ($position) · $position (integer) This method need to get a position number of text for remove but text entered by user into Entry field doesn't have a position number! – edem Jan 02 '13 at 15:02
  • One might expect that it would be either "0", or "1" after the user enters something. It would not be "VOID". – happy coder Jan 02 '13 at 16:00
  • Unfortunately the indexes is begun from 0 to N. 0 means the first value in a model ComboBoxEntry. So it doesn't work too. – edem Jan 02 '13 at 16:03
  • Well, if there is a method to tell you the number of entries, let's call it "N", then simply delete the "N-1"th entry. DONE – happy coder Jan 02 '13 at 18:38
  • Well, I didn't notice any methods, or properties which will help you know how many entries have been made in the comboBoxEntry, so if you make a variable to keep track of that then you can do what I mentioned in my comment above. I know it looks kinda kludgy but I don't see an easier way to do it in GTK2. CHEERS – happy coder Jan 02 '13 at 19:21