Gregory Gregory - 1 year ago 311
C# Question

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

Please look for example combolist:

"Book" , "Boat" , "Computer" , "Mouse" , "Zepelin"

If i enter bo it will be nice, if after popup results, i will see only:

"*Bo*ok" , "*bo*at"

I've got no book, and codes from visual c# don't help. Reading GTK is dificcult for me, becouse i'm only two-day c# programmer. 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:

(this is in php/jquery)

Is there any posibility to make something like this in GTK# ?

Answer Source

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;


There is no need to filter results.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download