tableview.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!DOCTYPE html>
  2. <!--[if IE]><![endif]-->
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <title>Table View </title>
  8. <meta name="viewport" content="width=device-width">
  9. <meta name="title" content="Table View ">
  10. <meta name="generator" content="docfx 2.59.4.0">
  11. <link rel="shortcut icon" href="../favicon.ico">
  12. <link rel="stylesheet" href="../styles/docfx.vendor.css">
  13. <link rel="stylesheet" href="../styles/docfx.css">
  14. <link rel="stylesheet" href="../styles/main.css">
  15. <link href="https://fonts.googleapis.com/css?family=Source Sans Pro" rel="stylesheet">
  16. <link href="https://fonts.googleapis.com/css?family=Source Code Pro" rel="stylesheet">
  17. <meta property="docfx:navrel" content="../toc.html">
  18. <meta property="docfx:tocrel" content="../toc.html">
  19. <meta property="docfx:rel" content="../">
  20. </head> <body data-spy="scroll" data-target="#affix" data-offset="120">
  21. <div id="wrapper">
  22. <header>
  23. <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
  24. <div class="container">
  25. <div class="navbar-header">
  26. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
  27. <span class="sr-only">Toggle navigation</span>
  28. <span class="icon-bar"></span>
  29. <span class="icon-bar"></span>
  30. <span class="icon-bar"></span>
  31. </button>
  32. <a class="navbar-brand" href="../index.html">
  33. <img id="logo" class="svg" src="../images/logo48.png" alt="">
  34. </a>
  35. </div>
  36. <div class="collapse navbar-collapse" id="navbar">
  37. <form class="navbar-form navbar-right" role="search" id="search">
  38. <div class="form-group">
  39. <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
  40. </div>
  41. </form>
  42. </div>
  43. </div>
  44. </nav>
  45. <div class="subnav navbar navbar-default">
  46. <div class="container hide-when-search" id="breadcrumb">
  47. <ul class="breadcrumb">
  48. <li></li>
  49. </ul>
  50. </div>
  51. </div>
  52. </header>
  53. <div class="container body-content">
  54. <div id="search-results">
  55. <div class="search-list">Search Results for <span></span></div>
  56. <div class="sr-items">
  57. <p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
  58. </div>
  59. <ul id="pagination" data-first="First" data-prev="Previous" data-next="Next" data-last="Last"></ul>
  60. </div>
  61. </div>
  62. <div role="main" class="container body-content hide-when-search">
  63. <div class="article row grid">
  64. <div class="col-md-10">
  65. <article class="content wrap" id="_content" data-uid="">
  66. <h1 id="table-view">Table View</h1>
  67. <p>This control supports viewing and editing tabular data. It provides a view of a <a href="https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable?view=net-5.0">System.DataTable</a>.</p>
  68. <p>System.DataTable is a core class of .net standard and can be created very easily</p>
  69. <p><a href="../api/Terminal.Gui/Terminal.Gui.TableView.html">TableView API Reference</a></p>
  70. <h2 id="csv-example">Csv Example</h2>
  71. <p>You can create a DataTable from a CSV file by creating a new instance and adding columns and rows as you read them. For a robust solution however you might want to look into a CSV parser library that deals with escaping, multi line rows etc.</p>
  72. <pre><code class="lang-csharp">var dt = new DataTable();
  73. var lines = File.ReadAllLines(filename);
  74. foreach(var h in lines[0].Split(&#39;,&#39;)){
  75. dt.Columns.Add(h);
  76. }
  77. foreach(var line in lines.Skip(1)) {
  78. dt.Rows.Add(line.Split(&#39;,&#39;));
  79. }
  80. </code></pre><h2 id="database-example">Database Example</h2>
  81. <p>All Ado.net database providers (Oracle, MySql, SqlServer etc) support reading data as DataTables for example:</p>
  82. <pre><code class="lang-csharp">var dt = new DataTable();
  83. using(var con = new SqlConnection(&quot;Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;&quot;))
  84. {
  85. con.Open();
  86. var cmd = new SqlCommand(&quot;select * from myTable;&quot;,con);
  87. var adapter = new SqlDataAdapter(cmd);
  88. adapter.Fill(dt);
  89. }
  90. </code></pre><h2 id="displaying-the-table">Displaying the table</h2>
  91. <p>Once you have set up your data table set it in the view:</p>
  92. <pre><code class="lang-csharp">tableView = new TableView () {
  93. X = 0,
  94. Y = 0,
  95. Width = 50,
  96. Height = 10,
  97. };
  98. tableView.Table = yourDataTable;
  99. </code></pre><h2 id="table-rendering">Table Rendering</h2>
  100. <p>TableView supports any size of table (limited only by the RAM requirements of <code>System.DataTable</code>). You can have
  101. thousands of columns and/or millions of rows if you want. Horizontal and vertical scrolling can be done using
  102. the mouse or keyboard.</p>
  103. <p>TableView uses <code>ColumnOffset</code> and <code>RowOffset</code> to determine the first visible cell of the <code>System.DataTable</code>.
  104. Rendering then continues until the avaialble console space is exhausted. Updating the <code>ColumnOffset</code> and
  105. <code>RowOffset</code> changes which part of the table is rendered (scrolls the viewport).</p>
  106. <p>This approach ensures that no matter how big the table, only a small number of columns/rows need to be
  107. evaluated for rendering.</p>
  108. </article>
  109. </div>
  110. <div class="hidden-sm col-md-2" role="complementary">
  111. <div class="sideaffix">
  112. <div class="contribution">
  113. <ul class="nav">
  114. <li>
  115. <a href="https://github.com/gui-cs/Terminal.Gui/blob/develop/docfx/articles/tableview.md/#L1" class="contribution-link">Improve this Doc</a>
  116. </li>
  117. </ul>
  118. </div>
  119. <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
  120. <h5>In This Article</h5>
  121. <div></div>
  122. </nav>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. <footer>
  128. <div class="grad-bottom"></div>
  129. <div class="footer">
  130. <div class="container">
  131. <span class="pull-right">
  132. <a href="#top">Back to top</a>
  133. </span>
  134. <span>Generated by <strong>DocFX</strong></span>
  135. </div>
  136. </div>
  137. </footer>
  138. </div>
  139. <script type="text/javascript" src="../styles/docfx.vendor.js"></script>
  140. <script type="text/javascript" src="../styles/docfx.js"></script>
  141. <script type="text/javascript" src="../styles/main.js"></script>
  142. </body>
  143. </html>