mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 16:27:55 +01:00
* WIP: Add ITableDataSource * WIP: Refactor TableView * WIP: Port CSVEditor * WIP: Port TableEditor * WIP: Port MultiColouredTable scenario * Fix bug of adding duplicate column styles * Update tests to use DataTableSource * Tidy up * Add EnumerableTableDataSource<T> * Add test for EnumerableTableDataSource * Add test for EnumerableTableDataSource * Add code example to xmldoc * Add ProcessTable scenario * Rename ITableDataSource to ITableSource and update docs * Rename EnumerableTableDataSource to EnumerableTableSource * Fixed Frame != Bounds; changed UICat Scenarios list to use tableview! * Fix scroll resetting in ProcessTable scenario * Fix unit tests by setting Frame to same as Bounds * Document why we have to measure our data for use with TableView --------- Co-authored-by: Tig Kindel <tig@users.noreply.github.com>
36 lines
938 B
C#
36 lines
938 B
C#
using System.Data;
|
|
using System.Linq;
|
|
|
|
namespace Terminal.Gui {
|
|
/// <summary>
|
|
/// <see cref="ITableSource"/> implementation that wraps
|
|
/// a <see cref="System.Data.DataTable"/>. This class is
|
|
/// mutable: changes are permitted to the wrapped <see cref="DataTable"/>.
|
|
/// </summary>
|
|
public class DataTableSource : ITableSource
|
|
{
|
|
private readonly DataTable table;
|
|
|
|
/// <summary>
|
|
/// Creates a new instance based on the data in <paramref name="table"/>.
|
|
/// </summary>
|
|
/// <param name="table"></param>
|
|
public DataTableSource(DataTable table)
|
|
{
|
|
this.table = table;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public object this [int row, int col] => table.Rows[row][col];
|
|
|
|
/// <inheritdoc/>
|
|
public int Rows => table.Rows.Count;
|
|
|
|
/// <inheritdoc/>
|
|
public int Columns => table.Columns.Count;
|
|
|
|
/// <inheritdoc/>
|
|
public string [] ColumnNames => table.Columns.Cast<DataColumn>().Select (c => c.ColumnName).ToArray ();
|
|
}
|
|
}
|