0

我在组合框中的项目很少,并且有 10 个输入字段。组合框中的每个项目都“连接”到 objct,当我从组合框中选择第一个项目时,它应该使用来自 objct 编号 1 的数据填充条目,当我选择第二个项目时,它应该使用来自对象 2 的数据......

要检查组合框中的哪些项目被选中,我使用:IdFieldComboBox.Active; 但我需要一直调用它,选择已更改。我应该用什么来做到这一点?

现在我使用 foucs 处理程序,但它不正确的解决方案:

    protected void OnIdFieldComboBoxFocusChildSet (object o, Gtk.FocusChildSetArgs args)
{

    unitNumber = IdFieldComboBox.Active;


}
4

1 回答 1

0

If I found the right GTK# ComboBox documentation, it is already spelled out for you. The sample has you using GetActiverIter which returns True/False on whether it is found, and if found, outputs the value to the TreeIter object passed in as an out.

 using System;
 using Gtk;
 class ComboBoxSample
 {
      static void Main ()
      {
           new ComboBoxSample ();
      }
      ComboBoxSample ()
      {
           Application.Init ();
           Window win = new Window ("ComboBoxSample");
           win.DeleteEvent += new DeleteEventHandler (OnWinDelete);
           ComboBox combo = ComboBox.NewText ();
           for (int i = 0; i < 5; i ++)
                combo.AppendText ("item " + i);
           combo.Changed += new EventHandler (OnComboBoxChanged);
           win.Add (combo);
           win.ShowAll ();
           Application.Run ();
      }
      void OnComboBoxChanged (object o, EventArgs args)
      {
           ComboBox combo = o as ComboBox;
           if (o == null)
                return;
           TreeIter iter;
           if (combo.GetActiveIter (out iter))
                Console.WriteLine ((string) combo.Model.GetValue (iter, 0));
      }
      void OnWinDelete (object obj, DeleteEventArgs args)
      {
           Application.Quit ();
      }
 }
于 2013-09-23T19:34:48.183 回答