diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 6ae8dd92f..e40354001 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -1,4 +1,5 @@ using System.Data; +using System.Globalization; namespace Terminal.Gui; @@ -16,7 +17,7 @@ public delegate ColorScheme RowColorGetterDelegate (RowColorGetterArgs args); /// View for tabular data based on a . /// See TableView Deep Dive for more information. /// -public class TableView : View +public class TableView : View, IDesignable { /// /// The default maximum cell width for and @@ -2307,4 +2308,62 @@ public class TableView : View /// The horizontal position to begin rendering the column at public int X { get; set; } } + + bool IDesignable.EnableForDesign () + { + var dt = BuildDemoDataTable (5, 5); + Table = new DataTableSource (dt); + return true; + } + + /// + /// Generates a new demo with the given number of (min 5) and + /// + /// + /// + /// + /// + public static DataTable BuildDemoDataTable (int cols, int rows) + { + var dt = new DataTable (); + + var explicitCols = 6; + dt.Columns.Add (new DataColumn ("StrCol", typeof (string))); + dt.Columns.Add (new DataColumn ("DateCol", typeof (DateTime))); + dt.Columns.Add (new DataColumn ("IntCol", typeof (int))); + dt.Columns.Add (new DataColumn ("DoubleCol", typeof (double))); + dt.Columns.Add (new DataColumn ("NullsCol", typeof (string))); + dt.Columns.Add (new DataColumn ("Unicode", typeof (string))); + + for (var i = 0; i < cols - explicitCols; i++) + { + dt.Columns.Add ("Column" + (i + explicitCols)); + } + + var r = new Random (100); + + for (var i = 0; i < rows; i++) + { + List row = new () + { + $"Demo text in row {i}", + new DateTime (2000 + i, 12, 25), + r.Next (i), + r.NextDouble () * i - 0.5 /*add some negatives to demo styles*/, + DBNull.Value, + "Les Mise" + + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + + "rables" + }; + + for (var j = 0; j < cols - explicitCols; j++) + { + row.Add ("SomeValue" + r.Next (100)); + } + + dt.Rows.Add (row.ToArray ()); + } + + return dt; + } } diff --git a/UICatalog/Scenarios/Generic.cs b/UICatalog/Scenarios/Generic.cs index 2bf6b96a4..dc9131623 100644 --- a/UICatalog/Scenarios/Generic.cs +++ b/UICatalog/Scenarios/Generic.cs @@ -1,3 +1,4 @@ +#nullable enable using Terminal.Gui; namespace UICatalog.Scenarios; diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index 7d18edc25..d324fedc3 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -344,57 +344,6 @@ public class TableEditor : Scenario private ColorScheme _redColorSchemeAlt; private TableView _tableView; - /// - /// Generates a new demo with the given number of (min 5) and - /// - /// - /// - /// - /// - public static DataTable BuildDemoDataTable (int cols, int rows) - { - var dt = new DataTable (); - - var explicitCols = 6; - dt.Columns.Add (new DataColumn ("StrCol", typeof (string))); - dt.Columns.Add (new DataColumn ("DateCol", typeof (DateTime))); - dt.Columns.Add (new DataColumn ("IntCol", typeof (int))); - dt.Columns.Add (new DataColumn ("DoubleCol", typeof (double))); - dt.Columns.Add (new DataColumn ("NullsCol", typeof (string))); - dt.Columns.Add (new DataColumn ("Unicode", typeof (string))); - - for (var i = 0; i < cols - explicitCols; i++) - { - dt.Columns.Add ("Column" + (i + explicitCols)); - } - - var r = new Random (100); - - for (var i = 0; i < rows; i++) - { - List row = new () - { - "Some long text that is super cool", - new DateTime (2000 + i, 12, 25), - r.Next (i), - r.NextDouble () * i - 0.5 /*add some negatives to demo styles*/, - DBNull.Value, - "Les Mise" - + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) - + "rables" - }; - - for (var j = 0; j < cols - explicitCols; j++) - { - row.Add ("SomeValue" + r.Next (100)); - } - - dt.Rows.Add (row.ToArray ()); - } - - return dt; - } - /// /// Builds a simple table in which cell values contents are the index of the cell. This helps testing that /// scrolling etc is working correctly and not skipping out any rows/columns when paging @@ -1006,7 +955,7 @@ public class TableEditor : Scenario private void OpenExample (bool big) { - SetTable (BuildDemoDataTable (big ? 30 : 5, big ? 1000 : 5)); + SetTable (TableView.BuildDemoDataTable (big ? 30 : 5, big ? 1000 : 5)); SetDemoTableStyles (); }