Skip to content

Commit

Permalink
Merge pull request #3686 from Remo/use-datacolumn-caption
Browse files Browse the repository at this point in the history
TableView: Use caption of data column if set to render label
  • Loading branch information
tig authored Aug 28, 2024
2 parents 6498610 + 18e4010 commit 9e86b7f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/TableView/DataTableSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public class DataTableSource : ITableSource
public int Columns => DataTable.Columns.Count;

/// <inheritdoc/>
public string [] ColumnNames => DataTable.Columns.Cast<DataColumn> ().Select (c => c.ColumnName).ToArray ();
public string [] ColumnNames => DataTable.Columns.Cast<DataColumn> ().Select (c => c.Caption).ToArray ();
}
23 changes: 23 additions & 0 deletions UnitTests/Views/TableViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3169,6 +3169,29 @@ public void TestToggleCells_MultiSelectOn_Two_SquareSelects_BothToggled ()
Assert.Equal (8, tableView.GetAllSelectedCells ().Count ());
}

[Fact]
public void TestDataColumnCaption()
{
var tableView = new TableView ();

var dt = new DataTable ();
dt.Columns.Add (new DataColumn ()
{
Caption = "Caption 1",
ColumnName = "Column Name 1"
});
dt.Columns.Add (new DataColumn ()
{
ColumnName = "Column Name 2"
});

var dts = new DataTableSource (dt);
var cn = dts.ColumnNames;

Assert.Equal ("Caption 1", cn [0]);
Assert.Equal ("Column Name 2", cn [1]);
}

private TableView GetABCDEFTableView (out DataTable dt)
{
var tableView = new TableView ();
Expand Down

0 comments on commit 9e86b7f

Please sign in to comment.