2012-04-23 7 views
1

私はC#/ Gtk#を学び、私自身の個人的な楽しさ/拷問のためにアプリの怪物になっています。私の最近の悩みは、ComboBoxEntryからアイテムをクリアする方法です。私はそれを行う方法を見つけましたが、それは私にクルージングのようです。Gtk# - ActiveTextをComboBoxEntryでクリアする適切な方法は?

Initial application load

私はそれをクリアするためのボタンをクリックすると、その後、アイテムが削除されますが、「FOO:ここ

は、私は、テキストとComboBoxEntryを作成し、それをクリアするには、ボタンをクリックして、私のテストのアプリです「まだアクティブなテキストとして残り:

Application with the combo cleared but still has that pesky foo in there

とにかく、私は次のコードでそれをクリアする方法を考え出しました。これを行うには良い方法があるはずと思われるが、私は1つが私は健全性チェックのためにここに来ている見つけることができません。

using System; 
using Gtk; 

public partial class MainWindow: Gtk.Window 
{ 
    ListStore comboModel1 = new ListStore (typeof(string)); 

    public MainWindow(): base (Gtk.WindowType.Toplevel) 
    { 
     Build(); 

     ComboBoxEntry1.Model = comboModel1; 
     comboModel1.AppendValues ("foo"); 

     // Set "foo" as selected item 
     Gtk.TreeIter iter; 
     ComboBoxEntry1.Model.IterNthChild (out iter, 0); 
     ComboBoxEntry1.SetActiveIter (iter); 
    } 

    protected void Button1OnClicked (object sender, System.EventArgs e) 
    { 
     // Just doing this .Clear() still leaves "foo" as the ActiveText 
     comboModel1.Clear(); 

     // My kludge to clear ActiveText 
     comboModel1.AppendValues (""); 

     Gtk.TreeIter iter; 
     ComboBoxEntry1.Model.IterNthChild (out iter, 0); 
     ComboBoxEntry1.SetActiveIter (iter); 

     comboModel1.Clear(); 
    } 

    protected void OnDeleteEvent (object sender, DeleteEventArgs a) 
    { 
     Application.Quit(); 
     a.RetVal = true; 
    } 
} 

感謝を! Jason

答えて

1

私はMacOS 10.7でそれをテストしました。シンプルなcomboModel1.Clear()はそのトリックを行います。 ActiveTextがなく、さらにListStoreに値が存在しないため、Combobox isntイベントはもはやアクセスできません。 これはおそらくWindows上のバグです。しかし、私はそれを疑うと、Windows上でもテストされます。 IterNthChildの代わりにヒントとして、GetIterFirstを使用することができます。

+0

あなたはComboboxEntryについて話しています。私は同じ行動を確認することができます。だから、混乱のために悲しい。 – Chris

関連する問題