Re: [Vala] Problems using ComboBox with model



Hi.

2010/2/9 Lars-Erik Helander <lehswe gmail com>:
Do anyone have a working example of using a ComboBox with model (not
the simple text API)?

Kind Regards

Lars

This piece of code should make things easier to understand:

---- CODE ----
using Gtk;

public class SampleApp : Window
{
    public SampleApp()
    {
        ListStore    model;
        ComboBox     combo;
        CellRenderer cell;
        int          i;

        this.title = "ComboBox sample application";
        this.destroy.connect( Gtk.main_quit );

        model = new ListStore( 2, typeof( string ), typeof( int ) );
        for( i = 0; i <= 100; i += 10 )
        {
            TreeIter iter;

            model.append( out iter );
            model.set( iter, 0, "Dummy text", 1, i );
        }

        combo = new ComboBox.with_model( model );
        this.add( combo );
        combo.show();

        cell = new CellRendererText();
        combo.pack_start( cell, false );
        combo.set_attributes( cell, "text", 0 );

        cell = new CellRendererProgress();
        combo.pack_start( cell, true );
        combo.set_attributes( cell, "value", 1 );
    }

    public static int main( string[] args )
    {
        SampleApp app;

        Gtk.init( ref args );

        app = new SampleApp();
        app.show();

        Gtk.main();

        return( 0 );
    }
}
---- CODE ----

Tadej

-- 
Tadej Borovšak
tadeboro.blogspot.com
tadeboro gmail com
tadej borovsak gmail com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]