[英]MONO GTK# Combobox entry - find entered value and set it to default
First, sorry for my English. 首先,对不起我的英语。 I don't use it often.
我不经常使用。
I'm learning Mono C# with GTK# on my Mac, and i've got problem with one function. 我在Mac上使用GTK#学习Mono C#,但我在使用一个功能时遇到了问题。 I've no idea what to crunch this.
我不知道该怎么处理。
This is my code: 这是我的代码:
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));
It's get searchString (what i enter into combobox entry, and search successfully for it on my combolist. But i want to filter results by letter, and show only that equals to entered text. 它是searchString(我要输入组合框条目,然后在组合列表上成功搜索它。但是我想按字母过滤结果,并仅显示等于输入的文本。
Please look for example combolist: 请查看示例组合列表:
"Book" , "Boat" , "Computer" , "Mouse" , "Zepelin" “书”,“船”,“计算机”,“鼠标”,“ Zepelin”
If i enter bo it will be nice, if after popup results, i will see only: 如果我输入bo会很好,如果弹出结果后,我只会看到:
"* Bo *ok" , "* bo *at" “ * Bo * ok”,“ * bo * at”
I've got no book, and codes from visual c# don't help. 我没有书,Visual C#的代码也无济于事。 Reading GTK is dificcult for me, becouse i'm only two-day c# programmer.
对我而言,阅读GTK实在是个难事,因为我只是为期2天的C#程序员。 I learn when i see example.
当我看到示例时,我会学习。
Thank for any help. 感谢您的帮助。
EDIT: Ok, this doesn't work - i found other solution for get first char of entered string. 编辑:好的,这行不通-我找到了获取输入字符串的第一个字符的其他解决方案。 But i wonder how to make "suggest" something like this:
但是我想知道如何使“建议”这样的东西:
IMAGE: http://i.stack.imgur.com/0AJo5.jpg (this is in php/jquery) 图像: http : //i.stack.imgur.com/0AJo5.jpg (在php / jquery中)
Is there any posibility to make something like this in GTK# ? 是否可以在GTK#中进行类似的事情?
I Found fully working sollution for me :-) 我找到了对我完全有效的解决方案:-)
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;
}
}
Link: http://api.xamarin.com/?link=T%3aGtk.EntryCompletion 链接: http : //api.xamarin.com/? link = T% 3aGtk.EntryCompletion
There is no need to filter results. 无需过滤结果。
Try sorting like this, and for look in when search with gtk# instead of mono 尝试像这样排序,并在使用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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.