Gtk#,CellRendererCombo,总是显示下拉,禁用输入?

Gtk#, CellRendererCombo, always show drop-down, disable typing?

代码如下,目前看起来是这样的:

  1. CellRendererCombo好像是CellRendererText,我必须双击它才能显示下拉列表。是否可以像这样一直显示下拉按钮?

  1. 目前,可以在组合框中键入内容。是否可以限制仅从现有值(男性、女性)中进行选择,而不允许输入新文本?

源代码

        st = new Gtk.TreeStore(typeof(string), typeof(int), typeof(string));
        st.AppendValues("Homer", 38, "male");
        st.AppendValues("Marge", 34, "female");

        MyTree.Model = st;

        var r1 = new Gtk.CellRendererText();
        var r2 = new Gtk.CellRendererText();
        var r3 = new Gtk.CellRendererCombo();
        var genders = new Gtk.ListStore(typeof(string));
        genders.AppendValues("male");
        genders.AppendValues("female");
        r3.Model = genders;
        r3.TextColumn = 0;
        r3.Editable = true;

        MyTree.Columns[0].PackStart(r1, false);
        MyTree.Columns[1].PackStart(r2, false);
        MyTree.Columns[2].PackStart(r3, false);

        MyTree.Columns[0].AddAttribute(r1, "text", 0);
        MyTree.Columns[1].AddAttribute(r2, "text", 1);
        MyTree.Columns[2].AddAttribute(r3, "text", 2);

您想将 has-entry 属性 设置为 False

这将导致类似(我不擅长 C#)的结果:

var r3 = new Gtk.CellRendererCombo();
r3.SetHasEntry(false); // or if that fails, use
r3.SetProperty('has-entry', false);