[Gtk-sharp-list] Decimals in CellRendererText

Walter Kempf gtk-sharp at indicium.za.net
Mon Aug 14 08:16:08 EDT 2006


Hi,

I'm not sure if this is the Right Way (tm) to do this, but here is my 
way/hack:

Construct your ListView/TreeView with a typeof(string) for that column. 
In your Edited event handler, do

<code>
double d;
TreeIter iter;
Store.GetIter(out iter, new TreePath(Args.Path));

try { d = ToDouble(Args.NewText); }

catch (FormatException)
{
    // Maybe display error message?
    return;
}

Store.SetValue(iter, COLUMN_NUM, d.ToString("F3"));
</code>

... where Store is your TreeView's ListStore/TreeStore and Args is the 
EditedArgs argument passed to the Edited event's handler. The 
d.ToString("F3") will show 3 decimals. Use .ToString("N") for 2 decimals 
and .ToString("Fx") for x decimal places.

Hope this helps.

Walter

Elmar Haneke wrote:
> Hi,
>
> I want to edit Values of type double within an Treeview. Therefore I did 
> user CellRendererText class for Display.
>
> How can I control how many decimals are shown? Currentliy I get a lot of 
> trailing "0" - I would prefer to see "1" instead of "1.000000".
>
> Elmar
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
>
>   



More information about the Gtk-sharp-list mailing list