2014-01-05 20 views
1

首先,对不起我的英文。我不经常使用它。MONO GTK#Combobox条目 - 找到输入值并将其设置为默认值

我在Mac上学习带GTK#的Mono C#,并且我遇到了一个函数的问题。我不知道该如何解决这个问题。

这是我的代码:

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)); 

这是得到搜索字符串(我进入组合框条目,并在我的combolist它成功地搜索,但我想筛选通过信函结果,并且只显示相等。要输入的文字

请认准例如combolist:

“尚书”, “船”, “电脑”, “鼠标”, “Zepelin”

如果我输入b Ø这将是很好,如果弹出后的结果,我只能看到:

“* * OK”,“* *在”

我没有书,码从视觉c#不帮忙。阅读GTK对我来说很难,因为我只有两天的c#程序员。当我看到例子时我学会了。

感谢您的帮助。

编辑:好吧,这不起作用 - 我发现其他解决方案获取输入字符串的第一个字符。但我不知道如何使“建议”是这样的:

IMAGE:http://i.stack.imgur.com/0AJo5.jpg (这是在PHP/jQuery的)

是否有posibility做这样的事情在GTK#?

回答

0

我发现完全工作sollution我:-)

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; 
    } 
} 

链接:http://api.xamarin.com/?link=T%3aGtk.EntryCompletion

没有必要对结果进行过滤。

-1

尝试排序是这样,而对于看在搜索时使用GTK#,而不是单

 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) 
+0

太嵌套,你需要清理这个 – TheWebs