Sign up

How to pass double value to ListStore's constructor

I would like to pass some double value to ListStore's constructor but it doesn't allows me to do.

import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.ListStore;
import gtk.TreeView;
import gtk.TreeViewColumn;
import gtk.TreeIter;
import gtk.CellRendererText;


class MyWindow: MainWindow
{
    Box mainBox;

    this()
    {
        super("Tree view exercise");
        setBorderWidth(10);
        mainBox = new Box(Orientation.HORIZONTAL, 0);
        add(mainBox);


        showAll();
    }
}

class InfoModel: ListStore /* model */
{
    this()
    {
        super([GType.STRING, GType.DOUBLE]);

    }

    void addGoods(string name, double price)
    {
        TreeIter iterator = createIter();
        setValue(iterator, 0, name);
        setValue(iterator, 1, price);
    }
}

class DisplayModel: TreeView /* view */
{
    TreeViewColumn articleColumn;
    TreeViewColumn priceColumn;

    this (ListStore model)
    {
        articleColumn = new TreeViewColumn("Article", new CellRendererText(), "text", 0);

    }

}

void main(string[] args)
{
    Main.init(args);
    new MyWindow();
    Main.run();
}

When I try to compile this program it gives this error message:

Error: none of the overloads of 'setValue' are callable using argument types (TreeIter, int, double), candidates are:

import/gtk/ListStore.d(273): gtk.ListStore.ListStore.setValue(TreeIter iter, int column, string value)
import/gtk/ListStore.d(281): gtk.ListStore.ListStore.setValue(TreeIter iter, int column, int value)
import/gtk/ListStore.d(569): gtk.ListStore.ListStore.setValue(TreeIter iter, int column, Value value)

Also is it possible to round this double to 2 decimal places when presenting data with GtkTreeView.

Re: How to pass double value to ListStore's constructor

On 01/14/2017 09:05 PM, Erdem wrote:

I would like to pass some double value to ListStore's constructor but it doesn't allows me to do.

import gobject.Value;

Value v = new Value(price);
setValue(iterator, 1, v);

Also is it possible to round this double to 2 decimal places when presenting data with GtkTreeView.

Use TreeViewColumn.setCellDataFunc(); to set an callback that is used to
render the data, and than set the text propery of the CellRenderer that
is passed to the callback to set the text to be displayed.

Re: How to pass double value to ListStore's constructor

Thanks.