diff --git a/Terminal.Gui/Views/TableView.cs b/Terminal.Gui/Views/TableView.cs index 0a9a8cc0c..7323e2772 100644 --- a/Terminal.Gui/Views/TableView.cs +++ b/Terminal.Gui/Views/TableView.cs @@ -26,6 +26,11 @@ namespace Terminal.Gui.Views { /// public Func RepresentationGetter; + /// + /// Defines the format for values e.g. "yyyy-MM-dd" for dates + /// + public string Format{get;set;} + /// /// Set the maximum width of the column in characters. This value will be ignored if more than the tables . Defaults to /// @@ -56,6 +61,13 @@ namespace Terminal.Gui.Views { /// public string GetRepresentation (object value) { + if(!string.IsNullOrWhiteSpace(Format)) { + + if(value is IFormattable f) + return f.ToString(Format,null); + } + + if(RepresentationGetter != null) return RepresentationGetter(value); diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index 3ee7f34aa..1767e8691 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -145,9 +145,7 @@ namespace UICatalog.Scenarios { var negativeRight = new ColumnStyle() { - RepresentationGetter = (v)=> v is double d ? - d.ToString("0.##"): - v.ToString(), + Format = "0.##", MinWidth = 10, AlignmentGetter = (v)=>v is double d ? // align negative values right