Search does not work for me via filtering

public class PoetsPage : Gtk.Box  {

    private Gtk.StringFilter sfilter;
    private Gtk.SearchEntry  search_entry;

    public PoetsPage () {
        GLib.Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0);

		var db = new ConnectDB ();
		db.load_all_poets ();
        var scroll = new Gtk.ScrolledWindow();
        var single_selection = new Gtk.SingleSelection(MW.list_all_poets);
        var factory = new Gtk.SignalListItemFactory ();
        var gridview = new Gtk.GridView(single_selection, factory);
        search_entry = new Gtk.SearchEntry ();
        sfilter = new Gtk.StringFilter (new Gtk.PropertyExpression (typeof (ItemPoets), null, "name")) ;
        sfilter.set_match_mode (Gtk.StringFilterMatchMode.PREFIX);
        this.append (search_entry);
        this.append (scroll);

    private void on_change_text_entry_search () {
        string  text = search_entry.get_text ();
        sfilter.set_search (text);

    private void factory_setup (SignalListItemFactory f, Object litem) {
		var listitem = litem as Gtk.ListItem;
        var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
        var image = new Gtk.Image ();
        image.set_pixel_size (180);
        box.append (image);
        var label = new Gtk.Label ("");
        label.set_wrap (true);
        label.set_width_chars (20);
        // label.set_ellipsize(Pango.EllipsizeMode.END);
        label.set_size_request (250, -1);
        box.append (label);
        listitem.set_child (box);

    private void factory_bind(SignalListItemFactory f, Object litem) {
		var listitem = litem as Gtk.ListItem;
        var item = listitem.get_item () as ItemPoets;
        var box = listitem.get_child ();
        var image = box.get_first_child () as Gtk.Image;
        var label = box.get_last_child () as Gtk.Label;
        var name =;
        label.set_label (name);
        image.set_from_icon_name ("poet1");

Search does not work for me via filtering
I expected this method to do the job

sfilter.set_search (text);

Is there anyone who can help me and I would like to thank them very much

Is there a generous man who would be so kind as to help us?
I have been searching for the solution in examples online for days to no avail.

In the code you’ve shared at least, you haven’t done anything with the filter. You need to wrap your model in a Gtk.FilterListModel using that filter.

Workbench has an example called List Model.

I’ve done this

        filter_model = new Gtk.FilterListModel (single_selection, sfilter);

But I didn’t know what to do next

That’s the wrong order. The outermost model should be the Gtk.SelectionModel.

If MW.list_all_poets is the underlying model, then:

var filter_model = new Gtk.FilterListModel (MW.list_all_poets, sfilter);
var single_selection = new Gtk.SingleSelection (filter_model);
1 Like

It works!
You deserve all the words of thanks, thank you very much
But I won’t let you rest for long, lol

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.