[Gtk-sharp-list] Re: TreeViewColumn alignment

Bryan Buchanan adslh3nu at tpg.com.au
Mon Jun 27 17:50:49 EDT 2005


> 
> Message: 9
> Date: Mon, 27 Jun 2005 19:21:56 +0530
> From: Benoy George <mumsp at hotpop.com>
> Subject: [Gtk-sharp-list] TreeViewColumn alignment
> To: gtk-sharp-list at lists.ximian.com
> Message-ID: <42C0047C.70408 at hotpop.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Dear Friends,
> 
> Please help me on how to right align a column in 
> Gtk.TreeViewColumn
> 
> My current column definitions are
> 
> 	col = new TreeViewColumn ();
> 	colr = new CellRendererText ();
> 	col.Title = "Expense";
> 	col.PackStart (colr, true);
> 	col.AddAttribute (colr, "text", 2);
> 	col.Alignment = 0.0f;
> 	col.Resizable = true;
> 	tv.AppendColumn (col);
> 
> I want to align above said column Expense to right-align 
> with two decimal point. I googled a lot, but no way to get 
> it done.
> 
col.Alignment = 1.0f;	// col title right aligned
colr.Xalign = 1.0f;	// render data right aligned

Depending how your data is stored in the model you might also need
 
col.SetCellDataFunc(colr, new TreeCellDataFunc(ShowExpense));

and

void ShowExpense (TreeViewColumn tree_column,
   CellRenderer cell, TreeModel tree_model, TreeIter iter)
{
  double x = (double) tree_model.GetValue(iter, 1);
  ((CellRendererText)cell).Text = String.Format("{0:N2}", x);
}

or similar.

Bryan



More information about the Gtk-sharp-list mailing list