C# MONO GTK#组合框条目-查找输入的值并将其设置为默认值

C# MONO GTK#组合框条目-查找输入的值并将其设置为默认值,c#,combobox,mono,gtk#,C#,Combobox,Mono,Gtk#,首先,对不起我的英语。我不经常用它 我在Mac上学习单声道C#和GTK#,我有一个函数有问题。我不知道该怎么处理这个 这是我的代码: var searchString = itemNameCombo.Entry.Text; string chk; TreeIter ti; itemNameCombo.Model.GetIterFirst (out ti); do { chk = itemNameCombo.Model.GetValue(ti, 0).ToString(); i

首先,对不起我的英语。我不经常用它

我在Mac上学习单声道C#和GTK#,我有一个函数有问题。我不知道该怎么处理这个

这是我的代码:

var searchString = itemNameCombo.Entry.Text;
string chk;

TreeIter ti;
itemNameCombo.Model.GetIterFirst (out ti);

do {
    chk = itemNameCombo.Model.GetValue(ti, 0).ToString();
    if(chk == searchString) {
        Console.WriteLine("Done - found"); itemNameCombo.SetActiveIter( ti );
        break;
    }
} while( itemNameCombo.Model.IterNext(ref ti));
它是GetSearchString(我在combobox条目中输入的内容,并在我的combolist中成功搜索它。但我想按字母筛选结果,只显示与输入的文本相等的内容)

请查看示例组合列表:

“书”、“船”、“计算机”、“鼠标”、“泽佩林”

如果我输入bo,这将很好,如果在弹出结果之后,我将只看到:

“*Bo*ok”、“*Bo*at”

我没有书,来自visual c的代码也没有帮助。阅读GTK对我来说是很难的,因为我只是两天的c程序员。我在看到示例时就会学习

谢谢你的帮助

编辑:好的,这不起作用-我找到了获取输入字符串的第一个字符的其他解决方案。但我想知道如何使“建议”类似于这样:

图片: (这是在php/jquery中)


有没有可能在GTK中制作类似的东西?

尝试这样的排序,并在使用GTK而不是mono搜索时查找

     string tempsearch=""
     string tempitem=""
     string searche=""
     list lista

     foreach itemString in combo
        foreach char in itemstring
           tempitem=temp+char
             foreach chars in search
               tempsearch= tempsearch+chars
                 if (tempsearch==tempitem)
                   lista.add(itemstring)

我找到了对我完全有效的解决方案:-)

使用系统;
使用Gtk;
公共类DemoEntryCompletion:窗口
{
静态空隙干管()
{
Application.Init();
新DemoEntryCompletion();
Application.Run();
}
publicdementrycompletion():base(“演示条目完成”)
{
此值为0.BorderWidth=10;
this.resizeable=false;
VBox VBox=新的VBox();
Label Label=新标签(“完成演示,例如尝试编写total或gnome”);
label.UseMarkup=true;
vbox.PackStart(标签,false,true,0);
条目=新条目();
entry.Completion=newentrycompletion();
entry.Completion.Model=CreateCompletionModel();
entry.Completion.TextColumn=0;
vbox.PackStart(条目,false,true,0);
添加(vbox);
this.ShowAll();
}
TreeModel CreateCompletionModel()
{
ListStore store=新的ListStore(typeof(string));
store.appendvalue(“GNOME”);
store.AppendValue(“总计”);
储存价值(“全部”);
退货店;
}
}
链接:


不需要筛选结果。

太嵌套了,您需要清理它
using System;
using Gtk;

public class DemoEntryCompletion : Window
{
    static void Main ()
    {
        Application.Init ();
        new DemoEntryCompletion ();
        Application.Run ();
    }

  public DemoEntryCompletion () : base ("Demo Entry Completion")
  {
    this.BorderWidth = 10;
    this.Resizable = false;
    VBox vbox = new VBox ();

    Label label = new Label ("Completion demo, try writing <b>total</b> or </b>gnome</b> for example.");
    label.UseMarkup = true;
    vbox.PackStart (label, false, true, 0);

    Entry entry = new Entry ();
    entry.Completion = new EntryCompletion ();
    entry.Completion.Model = CreateCompletionModel ();
    entry.Completion.TextColumn = 0;
    vbox.PackStart (entry, false, true, 0);

    this.Add (vbox);
    this.ShowAll ();
  }

  TreeModel CreateCompletionModel ()
  {
    ListStore store = new ListStore (typeof (string));

    store.AppendValues ("GNOME");
    store.AppendValues ("total");
      store.AppendValues ("totally");

    return store;
  }
}