[Gtk-sharp-list] treeview and doubles

Martin (OpenGeoMap) martin at opengeomap.org
Wed Apr 30 09:46:12 EDT 2008



> Hi,
>
> The way I did something similar was to make it a string column and have
> the cell renderer's Edited event handler check that the new string is a
> valid double. If so, you can format it yourself with the double's
> .toString("F6") (IIRC).
>
> Another way would be to define your own rendering methods, but I can't
> really remember how that story goes.
>
> Anyway... hope this helps and good luck!
>
> Walter
>
Problem solved thanks to Murray:

>> You can use gtk_tree_view_column_set_cell_data_func() to change how data
>> is displayed in your cell renderer. For instance, you can set the "text"
>> property with the result of a sprintf() call:
>> http://library.gnome.org/devel/gtk/unstable/GtkTreeViewColumn.html#gtk-tree-view-column-set-cell-data-func
>>
>> gtkmm even has a Gtk::TreeView::append_column_numeric() method to make
>> this easier:
>> http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1TreeView.html#e6fc0051cc178bfacea2dec27c2d5a58
>>
>>   
> Thank you so much, Murray. In ruby works fine also.
>
>     renderer = Gtk::CellRendererText.new
>     column = Gtk::TreeViewColumn.new("Prize", renderer,'text' => 
> PRIZE_COLUMN)
>     column.set_cell_data_func(renderer) {|column, cell, model, iter|
>     cell.text=sprintf("%.2f",iter[PRIZE_COLUMN])
>     }
>
>
> Ruby-gnome Rocks!!!!!!!!!!!!!!!!!
> Regards.




More information about the Gtk-sharp-list mailing list