Pastey Simple listview with Phix

<eucode>
--# Simple ListView  
 
include GtkMain.e 
include GtkWindow.e 
include GtkBox.e 
include GtkLabel.e 
include GtkScrolledWindow.e 
include GtkButtonBox.e 
include GtkButton.e 
include GtkListStore.e 
include GtkTreeView.e 
include GtkTreeSelection.e 
include GtkTreeViewColumn.e 
include GtkCellRendererText.e 
include GtkMessageDialog.e 
 
enum NAME,QTY,PRICE,BRAND 
constant fruits = {  
	{"Apples",   "doz",	3.50,	"Mackintosh"}, 
	{"Cherries", "lb",	2.69,	"Bing"}, 
	{"Dates",    "lb",	6.99,	"Medjool"}, 
	{"Limes",    "ea",	 .59,	"Key"}, 
	{"Oranges",  "ea",	 .79,	"Valencia"}, 
	{"Bananas",  "lb",	 .89,	"Dole"}, 
	$} 
 
Window win = new() 
 win.border_width = 10 
 win.default_size = {100,300} 
  
Box pan = new() 
 
Label lbl = new() 
 lbl.markup = "Simple list view" 
  
ScrolledWindow scrol = new()  
 
ButtonBox box = new() 
 
Button btn1 = new() 
 btn1.label = "gtk-quit" 
 btn1.connect("clicked","Quit") 
  
Button btn2 = new() 
 btn2.label = "gtk-ok" 
 btn2.connect("clicked","ShowChoice") 
 
object params = {gSTR,gSTR,gSTR,gSTR}  
ListStore store = new({params})  
 
TreeView tv = new()  
	tv.headers_visible = true 
	tv.tooltip_column = 4 
	tv.connect("row-activated","ShowChoice") 
	 
TreeViewColumn col1 = new()  
	col1.title = "Name" 
	col1.resizable = true 
	col1.visible = true 
	col1.reorderable = true 
CellRendererText r1 = new() 
	col1.pack_start(r1) 
	col1.add_attribute(r1,"text",1) 
	 
TreeViewColumn col2 = new() 
	col2.title = "Qty" 
	col2.resizable = true 
CellRendererText r2 = new() 
	col2.pack_start(r2) 
	col2.add_attribute(r2,"text",2) 
 
TreeViewColumn col3 = new() 
	col3.title = "Price" 
	col3.resizable = true 
CellRendererText r3 = new() 
	col3.pack_start(r3) 
	col3.add_attribute(r3,"text",3) 
 
{}=tv.append_column(col1) 
{}=tv.append_column(col2) 
{}=tv.append_column(col3) 
 
store.data = fruits  
tv.model = store 
 
box.add(btn1) 
box.add(btn2) 
 
win.add(pan) 
pan.pack_start(lbl) 
scrol.add_with_viewport(tv) 
pan.pack_start(scrol,1,1) 
pan.pack_end(box) 
 
win.show_all() 
gtk_main() 
 
----------------------------- 
public function ShowChoice() 
------------------------------ 
object row_data = tv.selection.selected_row_data 
 
MessageDialog dlg = new({"",win}) 
dlg.title = "Your Choice"  
dlg.markup = sprintf("%s %s",{row_data[BRAND],row_data[NAME]}) 
dlg.secondary = sprintf("$%2.2f %s", 
 {to_number(row_data[PRICE]),row_data[QTY]}) 
  
object response = dlg.run() 
dlg.destroy() 
return response 
end function 

</eucode>

1. Comment by irv in January

Note that the price column is numeric, but the price column is declared as gSTR. The value is automatically formatted as %2.2f, which serves most purposes.