Gtk#,CellRendererCombo,始终显示下拉菜单,禁用打字?

问题描述 投票:0回答:1

代码如下,目前看起来像这样: enter image description here

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

enter image description here

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

源代码

        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);
c# gtk gtk3 gtk#
1个回答
0
投票

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

False

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

var r3 = new Gtk.CellRendererCombo();
r3.SetHasEntry(false); // or if that fails, use
r3.SetProperty('has-entry', false);
© www.soinside.com 2019 - 2024. All rights reserved.