From b9b4253a5d2294e01ad3ac96cb80619aa88d6328 Mon Sep 17 00:00:00 2001 From: Lynne Date: Thu, 3 Sep 2020 16:34:42 +1000 Subject: [PATCH] i am not good at c# --- MainWindow.cs | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/MainWindow.cs b/MainWindow.cs index 9d2e81e..334095f 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -26,11 +26,11 @@ using Gtk; namespace Buypeeb { public struct ItemColumns { - public static int Name = 0; - public static int PriceYen = 1; - public static int PriceAUD = 2; - public static int Ending = 3; - public static int Id = 4; + public const int Name = 0; + public const int PriceYen = 1; + public const int PriceAUD = 2; + public const int Ending = 3; + public const int Id = 4; } class MainWindow : Window { @@ -56,11 +56,28 @@ namespace Buypeeb { this.RenderList(); this.itemTreeView.Model = this.items; - //TODO: make this less verbose - this.itemTreeView.Columns[ItemColumns.Name].SetCellDataFunc(this.itemTreeView.Columns[ItemColumns.Name].Cells[0], new Gtk.TreeCellDataFunc(this.RenderColumnName)); - this.itemTreeView.Columns[ItemColumns.PriceYen].SetCellDataFunc(this.itemTreeView.Columns[ItemColumns.PriceYen].Cells[0], new Gtk.TreeCellDataFunc(this.RenderColumnPriceYen)); - this.itemTreeView.Columns[ItemColumns.PriceAUD].SetCellDataFunc(this.itemTreeView.Columns[ItemColumns.PriceAUD].Cells[0], new Gtk.TreeCellDataFunc(this.RenderColumnPriceAUD)); - this.itemTreeView.Columns[ItemColumns.Ending].SetCellDataFunc(this.itemTreeView.Columns[ItemColumns.Ending].Cells[0], new Gtk.TreeCellDataFunc(this.RenderColumnEnding)); + for (int i = 0; i < this.itemTreeView.Columns.Length; i++) { + var c = this.itemTreeView.Columns[i]; + var func = new Gtk.TreeCellDataFunc(this.RenderColumnName); + + //TODO: get rid of this awful if statement + + if (i == ItemColumns.PriceYen) { + func = new Gtk.TreeCellDataFunc(this.RenderColumnPriceYen); + } + else if (i == ItemColumns.PriceAUD) { + func = new Gtk.TreeCellDataFunc(this.RenderColumnPriceAUD); + } + else if (i == ItemColumns.Ending) { + func = new Gtk.TreeCellDataFunc(this.RenderColumnEnding); + } + else { + throw new IndexOutOfRangeException(); + } + + c.SetCellDataFunc(c.Cells[0], func); + } + foreach (object[] row in this.items) { Console.WriteLine(row[0]);