TableViewTests.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Terminal.Gui;
  7. using Xunit;
  8. using System.Globalization;
  9. using Xunit.Abstractions;
  10. using System.Reflection;
  11. namespace Terminal.Gui.Views {
  12. public class TableViewTests {
  13. readonly ITestOutputHelper output;
  14. public TableViewTests (ITestOutputHelper output)
  15. {
  16. this.output = output;
  17. }
  18. [Fact]
  19. public void EnsureValidScrollOffsets_WithNoCells ()
  20. {
  21. var tableView = new TableView ();
  22. Assert.Equal (0, tableView.RowOffset);
  23. Assert.Equal (0, tableView.ColumnOffset);
  24. // Set empty table
  25. tableView.Table = new DataTable ();
  26. // Since table has no rows or columns scroll offset should default to 0
  27. tableView.EnsureValidScrollOffsets ();
  28. Assert.Equal (0, tableView.RowOffset);
  29. Assert.Equal (0, tableView.ColumnOffset);
  30. }
  31. [Fact]
  32. public void EnsureValidScrollOffsets_LoadSmallerTable ()
  33. {
  34. var tableView = new TableView ();
  35. tableView.Bounds = new Rect (0, 0, 25, 10);
  36. Assert.Equal (0, tableView.RowOffset);
  37. Assert.Equal (0, tableView.ColumnOffset);
  38. // Set big table
  39. tableView.Table = BuildTable (25, 50);
  40. // Scroll down and along
  41. tableView.RowOffset = 20;
  42. tableView.ColumnOffset = 10;
  43. tableView.EnsureValidScrollOffsets ();
  44. // The scroll should be valid at the moment
  45. Assert.Equal (20, tableView.RowOffset);
  46. Assert.Equal (10, tableView.ColumnOffset);
  47. // Set small table
  48. tableView.Table = BuildTable (2, 2);
  49. // Setting a small table should automatically trigger fixing the scroll offsets to ensure valid cells
  50. Assert.Equal (0, tableView.RowOffset);
  51. Assert.Equal (0, tableView.ColumnOffset);
  52. // Trying to set invalid indexes should not be possible
  53. tableView.RowOffset = 20;
  54. tableView.ColumnOffset = 10;
  55. Assert.Equal (1, tableView.RowOffset);
  56. Assert.Equal (1, tableView.ColumnOffset);
  57. }
  58. [Fact]
  59. [AutoInitShutdown]
  60. public void Redraw_EmptyTable ()
  61. {
  62. var tableView = new TableView ();
  63. tableView.ColorScheme = new ColorScheme();
  64. tableView.Bounds = new Rect (0, 0, 25, 10);
  65. // Set a table with 1 column
  66. tableView.Table = BuildTable (1, 50);
  67. tableView.Redraw(tableView.Bounds);
  68. tableView.Table.Columns.Remove(tableView.Table.Columns[0]);
  69. tableView.Redraw(tableView.Bounds);
  70. }
  71. [Fact]
  72. public void SelectedCellChanged_NotFiredForSameValue ()
  73. {
  74. var tableView = new TableView () {
  75. Table = BuildTable (25, 50)
  76. };
  77. bool called = false;
  78. tableView.SelectedCellChanged += (e) => { called = true; };
  79. Assert.Equal (0, tableView.SelectedColumn);
  80. Assert.False (called);
  81. // Changing value to same as it already was should not raise an event
  82. tableView.SelectedColumn = 0;
  83. Assert.False (called);
  84. tableView.SelectedColumn = 10;
  85. Assert.True (called);
  86. }
  87. [Fact]
  88. public void SelectedCellChanged_SelectedColumnIndexesCorrect ()
  89. {
  90. var tableView = new TableView () {
  91. Table = BuildTable (25, 50)
  92. };
  93. bool called = false;
  94. tableView.SelectedCellChanged += (e) => {
  95. called = true;
  96. Assert.Equal (0, e.OldCol);
  97. Assert.Equal (10, e.NewCol);
  98. };
  99. tableView.SelectedColumn = 10;
  100. Assert.True (called);
  101. }
  102. [Fact]
  103. public void SelectedCellChanged_SelectedRowIndexesCorrect ()
  104. {
  105. var tableView = new TableView () {
  106. Table = BuildTable (25, 50)
  107. };
  108. bool called = false;
  109. tableView.SelectedCellChanged += (e) => {
  110. called = true;
  111. Assert.Equal (0, e.OldRow);
  112. Assert.Equal (10, e.NewRow);
  113. };
  114. tableView.SelectedRow = 10;
  115. Assert.True (called);
  116. }
  117. [Fact]
  118. public void Test_SumColumnWidth_UnicodeLength ()
  119. {
  120. Assert.Equal (11, "hello there".Sum (c => Rune.ColumnWidth (c)));
  121. // Creates a string with the peculiar (french?) r symbol
  122. String surrogate = "Les Mise" + Char.ConvertFromUtf32 (Int32.Parse ("0301", NumberStyles.HexNumber)) + "rables";
  123. // The unicode width of this string is shorter than the string length!
  124. Assert.Equal (14, surrogate.Sum (c => Rune.ColumnWidth (c)));
  125. Assert.Equal (15, surrogate.Length);
  126. }
  127. [Fact]
  128. public void IsSelected_MultiSelectionOn_Vertical ()
  129. {
  130. var tableView = new TableView () {
  131. Table = BuildTable (25, 50),
  132. MultiSelect = true
  133. };
  134. // 3 cell vertical selection
  135. tableView.SetSelection (1, 1, false);
  136. tableView.SetSelection (1, 3, true);
  137. Assert.False (tableView.IsSelected (0, 0));
  138. Assert.False (tableView.IsSelected (1, 0));
  139. Assert.False (tableView.IsSelected (2, 0));
  140. Assert.False (tableView.IsSelected (0, 1));
  141. Assert.True (tableView.IsSelected (1, 1));
  142. Assert.False (tableView.IsSelected (2, 1));
  143. Assert.False (tableView.IsSelected (0, 2));
  144. Assert.True (tableView.IsSelected (1, 2));
  145. Assert.False (tableView.IsSelected (2, 2));
  146. Assert.False (tableView.IsSelected (0, 3));
  147. Assert.True (tableView.IsSelected (1, 3));
  148. Assert.False (tableView.IsSelected (2, 3));
  149. Assert.False (tableView.IsSelected (0, 4));
  150. Assert.False (tableView.IsSelected (1, 4));
  151. Assert.False (tableView.IsSelected (2, 4));
  152. }
  153. [Fact]
  154. public void IsSelected_MultiSelectionOn_Horizontal ()
  155. {
  156. var tableView = new TableView () {
  157. Table = BuildTable (25, 50),
  158. MultiSelect = true
  159. };
  160. // 2 cell horizontal selection
  161. tableView.SetSelection (1, 0, false);
  162. tableView.SetSelection (2, 0, true);
  163. Assert.False (tableView.IsSelected (0, 0));
  164. Assert.True (tableView.IsSelected (1, 0));
  165. Assert.True (tableView.IsSelected (2, 0));
  166. Assert.False (tableView.IsSelected (3, 0));
  167. Assert.False (tableView.IsSelected (0, 1));
  168. Assert.False (tableView.IsSelected (1, 1));
  169. Assert.False (tableView.IsSelected (2, 1));
  170. Assert.False (tableView.IsSelected (3, 1));
  171. }
  172. [Fact]
  173. public void IsSelected_MultiSelectionOn_BoxSelection ()
  174. {
  175. var tableView = new TableView () {
  176. Table = BuildTable (25, 50),
  177. MultiSelect = true
  178. };
  179. // 4 cell horizontal in box 2x2
  180. tableView.SetSelection (0, 0, false);
  181. tableView.SetSelection (1, 1, true);
  182. Assert.True (tableView.IsSelected (0, 0));
  183. Assert.True (tableView.IsSelected (1, 0));
  184. Assert.False (tableView.IsSelected (2, 0));
  185. Assert.True (tableView.IsSelected (0, 1));
  186. Assert.True (tableView.IsSelected (1, 1));
  187. Assert.False (tableView.IsSelected (2, 1));
  188. Assert.False (tableView.IsSelected (0, 2));
  189. Assert.False (tableView.IsSelected (1, 2));
  190. Assert.False (tableView.IsSelected (2, 2));
  191. }
  192. [AutoInitShutdown]
  193. [Fact]
  194. public void PageDown_ExcludesHeaders ()
  195. {
  196. var tableView = new TableView () {
  197. Table = BuildTable (25, 50),
  198. MultiSelect = true,
  199. Bounds = new Rect (0, 0, 10, 5)
  200. };
  201. // Header should take up 2 lines
  202. tableView.Style.ShowHorizontalHeaderOverline = false;
  203. tableView.Style.ShowHorizontalHeaderUnderline = true;
  204. tableView.Style.AlwaysShowHeaders = false;
  205. // ensure that TableView has the input focus
  206. Application.Top.Add (tableView);
  207. Application.Top.FocusFirst ();
  208. Assert.True (tableView.HasFocus);
  209. Assert.Equal (0, tableView.RowOffset);
  210. tableView.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ()));
  211. // window height is 5 rows 2 are header so page down should give 3 new rows
  212. Assert.Equal (3, tableView.SelectedRow);
  213. Assert.Equal (1, tableView.RowOffset);
  214. // header is no longer visible so page down should give 5 new rows
  215. tableView.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ()));
  216. Assert.Equal (8, tableView.SelectedRow);
  217. Assert.Equal (4, tableView.RowOffset);
  218. }
  219. [Fact]
  220. public void DeleteRow_SelectAll_AdjustsSelectionToPreventOverrun ()
  221. {
  222. // create a 4 by 4 table
  223. var tableView = new TableView () {
  224. Table = BuildTable (4, 4),
  225. MultiSelect = true,
  226. Bounds = new Rect (0, 0, 10, 5)
  227. };
  228. tableView.SelectAll ();
  229. Assert.Equal (16, tableView.GetAllSelectedCells ().Count ());
  230. // delete one of the columns
  231. tableView.Table.Columns.RemoveAt (2);
  232. // table should now be 3x4
  233. Assert.Equal (12, tableView.GetAllSelectedCells ().Count ());
  234. // remove a row
  235. tableView.Table.Rows.RemoveAt (1);
  236. // table should now be 3x3
  237. Assert.Equal (9, tableView.GetAllSelectedCells ().Count ());
  238. }
  239. [Fact]
  240. public void DeleteRow_SelectLastRow_AdjustsSelectionToPreventOverrun ()
  241. {
  242. // create a 4 by 4 table
  243. var tableView = new TableView () {
  244. Table = BuildTable (4, 4),
  245. MultiSelect = true,
  246. Bounds = new Rect (0, 0, 10, 5)
  247. };
  248. // select the last row
  249. tableView.MultiSelectedRegions.Clear ();
  250. tableView.MultiSelectedRegions.Push (new TableView.TableSelection (new Point (0, 3), new Rect (0, 3, 4, 1)));
  251. Assert.Equal (4, tableView.GetAllSelectedCells ().Count ());
  252. // remove a row
  253. tableView.Table.Rows.RemoveAt (0);
  254. tableView.EnsureValidSelection ();
  255. // since the selection no longer exists it should be removed
  256. Assert.Empty (tableView.MultiSelectedRegions);
  257. }
  258. [Theory]
  259. [InlineData (true)]
  260. [InlineData (false)]
  261. public void GetAllSelectedCells_SingleCellSelected_ReturnsOne (bool multiSelect)
  262. {
  263. var tableView = new TableView () {
  264. Table = BuildTable (3, 3),
  265. MultiSelect = multiSelect,
  266. Bounds = new Rect (0, 0, 10, 5)
  267. };
  268. tableView.SetSelection (1, 1, false);
  269. Assert.Single (tableView.GetAllSelectedCells ());
  270. Assert.Equal (new Point (1, 1), tableView.GetAllSelectedCells ().Single ());
  271. }
  272. [Fact]
  273. public void GetAllSelectedCells_SquareSelection_ReturnsFour ()
  274. {
  275. var tableView = new TableView () {
  276. Table = BuildTable (3, 3),
  277. MultiSelect = true,
  278. Bounds = new Rect (0, 0, 10, 5)
  279. };
  280. // move cursor to 1,1
  281. tableView.SetSelection (1, 1, false);
  282. // spread selection across to 2,2 (e.g. shift+right then shift+down)
  283. tableView.SetSelection (2, 2, true);
  284. var selected = tableView.GetAllSelectedCells ().ToArray ();
  285. Assert.Equal (4, selected.Length);
  286. Assert.Equal (new Point (1, 1), selected [0]);
  287. Assert.Equal (new Point (2, 1), selected [1]);
  288. Assert.Equal (new Point (1, 2), selected [2]);
  289. Assert.Equal (new Point (2, 2), selected [3]);
  290. }
  291. [Fact]
  292. public void GetAllSelectedCells_SquareSelection_FullRowSelect ()
  293. {
  294. var tableView = new TableView () {
  295. Table = BuildTable (3, 3),
  296. MultiSelect = true,
  297. FullRowSelect = true,
  298. Bounds = new Rect (0, 0, 10, 5)
  299. };
  300. // move cursor to 1,1
  301. tableView.SetSelection (1, 1, false);
  302. // spread selection across to 2,2 (e.g. shift+right then shift+down)
  303. tableView.SetSelection (2, 2, true);
  304. var selected = tableView.GetAllSelectedCells ().ToArray ();
  305. Assert.Equal (6, selected.Length);
  306. Assert.Equal (new Point (0, 1), selected [0]);
  307. Assert.Equal (new Point (1, 1), selected [1]);
  308. Assert.Equal (new Point (2, 1), selected [2]);
  309. Assert.Equal (new Point (0, 2), selected [3]);
  310. Assert.Equal (new Point (1, 2), selected [4]);
  311. Assert.Equal (new Point (2, 2), selected [5]);
  312. }
  313. [Fact]
  314. public void GetAllSelectedCells_TwoIsolatedSelections_ReturnsSix ()
  315. {
  316. var tableView = new TableView () {
  317. Table = BuildTable (20, 20),
  318. MultiSelect = true,
  319. Bounds = new Rect (0, 0, 10, 5)
  320. };
  321. /*
  322. Sets up disconnected selections like:
  323. 00000000000
  324. 01100000000
  325. 01100000000
  326. 00000001100
  327. 00000000000
  328. */
  329. tableView.MultiSelectedRegions.Clear ();
  330. tableView.MultiSelectedRegions.Push (new TableView.TableSelection (new Point (1, 1), new Rect (1, 1, 2, 2)));
  331. tableView.MultiSelectedRegions.Push (new TableView.TableSelection (new Point (7, 3), new Rect (7, 3, 2, 1)));
  332. tableView.SelectedColumn = 8;
  333. tableView.SelectedRow = 3;
  334. var selected = tableView.GetAllSelectedCells ().ToArray ();
  335. Assert.Equal (6, selected.Length);
  336. Assert.Equal (new Point (1, 1), selected [0]);
  337. Assert.Equal (new Point (2, 1), selected [1]);
  338. Assert.Equal (new Point (1, 2), selected [2]);
  339. Assert.Equal (new Point (2, 2), selected [3]);
  340. Assert.Equal (new Point (7, 3), selected [4]);
  341. Assert.Equal (new Point (8, 3), selected [5]);
  342. }
  343. [Fact]
  344. public void TableView_ExpandLastColumn_True ()
  345. {
  346. var tv = SetUpMiniTable ();
  347. // the thing we are testing
  348. tv.Style.ExpandLastColumn = true;
  349. tv.Redraw (tv.Bounds);
  350. string expected = @"
  351. ┌─┬──────┐
  352. │A│B │
  353. ├─┼──────┤
  354. │1│2 │
  355. ";
  356. TestHelpers.AssertDriverContentsAre (expected, output);
  357. // Shutdown must be called to safely clean up Application if Init has been called
  358. Application.Shutdown ();
  359. }
  360. [Fact]
  361. public void TableView_ExpandLastColumn_False ()
  362. {
  363. var tv = SetUpMiniTable ();
  364. // the thing we are testing
  365. tv.Style.ExpandLastColumn = false;
  366. tv.Redraw (tv.Bounds);
  367. string expected = @"
  368. ┌─┬─┬────┐
  369. │A│B│ │
  370. ├─┼─┼────┤
  371. │1│2│ │
  372. ";
  373. TestHelpers.AssertDriverContentsAre (expected, output);
  374. // Shutdown must be called to safely clean up Application if Init has been called
  375. Application.Shutdown ();
  376. }
  377. [Fact]
  378. public void TableView_ExpandLastColumn_False_ExactBounds ()
  379. {
  380. var tv = SetUpMiniTable ();
  381. // the thing we are testing
  382. tv.Style.ExpandLastColumn = false;
  383. // width exactly matches the max col widths
  384. tv.Bounds = new Rect (0, 0, 5, 4);
  385. tv.Redraw (tv.Bounds);
  386. string expected = @"
  387. ┌─┬─┐
  388. │A│B│
  389. ├─┼─┤
  390. │1│2│
  391. ";
  392. TestHelpers.AssertDriverContentsAre (expected, output);
  393. // Shutdown must be called to safely clean up Application if Init has been called
  394. Application.Shutdown ();
  395. }
  396. [Fact]
  397. [AutoInitShutdown]
  398. public void TableView_Activate()
  399. {
  400. string activatedValue = null;
  401. var tv = new TableView (BuildTable(1,1));
  402. tv.CellActivated += (c) => activatedValue = c.Table.Rows[c.Row][c.Col].ToString();
  403. Application.Top.Add (tv);
  404. Application.Begin (Application.Top);
  405. // pressing enter should activate the first cell (selected cell)
  406. tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  407. Assert.Equal ("R0C0",activatedValue);
  408. // reset the test
  409. activatedValue = null;
  410. // clear keybindings and ensure that Enter does not trigger the event anymore
  411. tv.ClearKeybindings ();
  412. tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  413. Assert.Null(activatedValue);
  414. // New method for changing the activation key
  415. tv.AddKeyBinding (Key.z, Command.Accept);
  416. tv.ProcessKey (new KeyEvent (Key.z, new KeyModifiers ()));
  417. Assert.Equal ("R0C0", activatedValue);
  418. // reset the test
  419. activatedValue = null;
  420. tv.ClearKeybindings ();
  421. // Old method for changing the activation key
  422. tv.CellActivationKey = Key.z;
  423. tv.ProcessKey (new KeyEvent (Key.z, new KeyModifiers ()));
  424. Assert.Equal ("R0C0", activatedValue);
  425. }
  426. [Fact]
  427. public void TableViewMultiSelect_CannotFallOffLeft()
  428. {
  429. var tv = SetUpMiniTable ();
  430. tv.Table.Rows.Add (1, 2); // add another row (brings us to 2 rows)
  431. tv.MultiSelect = true;
  432. tv.SelectedColumn = 1;
  433. tv.SelectedRow = 1;
  434. tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers { Shift = true }));
  435. Assert.Equal (new Rect (0, 1, 2, 1), tv.MultiSelectedRegions.Single().Rect);
  436. // this next shift left should be ignored because we are already at the bounds
  437. tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers { Shift = true }));
  438. Assert.Equal (new Rect (0, 1, 2, 1), tv.MultiSelectedRegions.Single ().Rect);
  439. Assert.Equal (0, tv.SelectedColumn);
  440. Assert.Equal (1, tv.SelectedRow);
  441. Application.Shutdown ();
  442. }
  443. [Fact]
  444. public void TableViewMultiSelect_CannotFallOffRight()
  445. {
  446. var tv = SetUpMiniTable ();
  447. tv.Table.Rows.Add (1, 2); // add another row (brings us to 2 rows)
  448. tv.MultiSelect = true;
  449. tv.SelectedColumn = 0;
  450. tv.SelectedRow = 1;
  451. tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers { Shift = true }));
  452. Assert.Equal (new Rect (0, 1, 2, 1), tv.MultiSelectedRegions.Single ().Rect);
  453. // this next shift right should be ignored because we are already at the right bounds
  454. tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers { Shift = true }));
  455. Assert.Equal (new Rect (0, 1, 2, 1), tv.MultiSelectedRegions.Single ().Rect);
  456. Assert.Equal (1, tv.SelectedColumn);
  457. Assert.Equal (1, tv.SelectedRow);
  458. Application.Shutdown ();
  459. }
  460. [Fact]
  461. public void TableViewMultiSelect_CannotFallOffBottom ()
  462. {
  463. var tv = SetUpMiniTable ();
  464. tv.Table.Rows.Add (1, 2); // add another row (brings us to 2 rows)
  465. tv.MultiSelect = true;
  466. tv.SelectedColumn = 0;
  467. tv.SelectedRow = 0;
  468. tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers { Shift = true }));
  469. tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers { Shift = true }));
  470. Assert.Equal (new Rect (0, 0, 2, 2), tv.MultiSelectedRegions.Single ().Rect);
  471. // this next moves should be ignored because we already selected the whole table
  472. tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers { Shift = true }));
  473. tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers { Shift = true }));
  474. Assert.Equal (new Rect (0, 0, 2, 2), tv.MultiSelectedRegions.Single ().Rect);
  475. Assert.Equal (1, tv.SelectedColumn);
  476. Assert.Equal (1, tv.SelectedRow);
  477. Application.Shutdown ();
  478. }
  479. [Fact]
  480. public void TableViewMultiSelect_CannotFallOffTop()
  481. {
  482. var tv = SetUpMiniTable ();
  483. tv.Table.Rows.Add (1, 2); // add another row (brings us to 2 rows)
  484. tv.MultiSelect = true;
  485. tv.SelectedColumn = 1;
  486. tv.SelectedRow = 1;
  487. tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers { Shift = true }));
  488. tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers { Shift = true }));
  489. Assert.Equal (new Rect (0, 0, 2, 2), tv.MultiSelectedRegions.Single ().Rect);
  490. // this next moves should be ignored because we already selected the whole table
  491. tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers { Shift = true }));
  492. tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers { Shift = true }));
  493. Assert.Equal (new Rect (0, 0, 2, 2), tv.MultiSelectedRegions.Single ().Rect);
  494. Assert.Equal (0, tv.SelectedColumn);
  495. Assert.Equal (0, tv.SelectedRow);
  496. Application.Shutdown ();
  497. }
  498. [Theory]
  499. [InlineData (false)]
  500. [InlineData (true)]
  501. public void TableView_ColorTests_FocusedOrNot (bool focused)
  502. {
  503. var tv = SetUpMiniTable ();
  504. // width exactly matches the max col widths
  505. tv.Bounds = new Rect (0, 0, 5, 4);
  506. // private method for forcing the view to be focused/not focused
  507. var setFocusMethod = typeof (View).GetMethod ("SetHasFocus", BindingFlags.Instance | BindingFlags.NonPublic);
  508. // when the view is/isn't focused
  509. setFocusMethod.Invoke (tv, new object [] { focused, tv, true });
  510. tv.Redraw (tv.Bounds);
  511. string expected = @"
  512. ┌─┬─┐
  513. │A│B│
  514. ├─┼─┤
  515. │1│2│
  516. ";
  517. TestHelpers.AssertDriverContentsAre (expected, output);
  518. string expectedColors = @"
  519. 00000
  520. 00000
  521. 00000
  522. 01000
  523. ";
  524. TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
  525. // 0
  526. tv.ColorScheme.Normal,
  527. // 1
  528. focused ? tv.ColorScheme.HotFocus : tv.ColorScheme.HotNormal});
  529. Application.Shutdown();
  530. }
  531. [Theory]
  532. [InlineData (false)]
  533. [InlineData (true)]
  534. public void TableView_ColorTests_InvertSelectedCellFirstCharacter (bool focused)
  535. {
  536. var tv = SetUpMiniTable ();
  537. tv.Style.InvertSelectedCellFirstCharacter = true;
  538. // width exactly matches the max col widths
  539. tv.Bounds = new Rect (0, 0, 5, 4);
  540. // private method for forcing the view to be focused/not focused
  541. var setFocusMethod = typeof (View).GetMethod ("SetHasFocus", BindingFlags.Instance | BindingFlags.NonPublic);
  542. // when the view is/isn't focused
  543. setFocusMethod.Invoke (tv, new object [] { focused, tv, true });
  544. tv.Redraw (tv.Bounds);
  545. string expected = @"
  546. ┌─┬─┐
  547. │A│B│
  548. ├─┼─┤
  549. │1│2│
  550. ";
  551. TestHelpers.AssertDriverContentsAre (expected, output);
  552. string expectedColors = @"
  553. 00000
  554. 00000
  555. 00000
  556. 01000
  557. ";
  558. var invertHotFocus = new Attribute(tv.ColorScheme.HotFocus.Background,tv.ColorScheme.HotFocus.Foreground);
  559. var invertHotNormal = new Attribute(tv.ColorScheme.HotNormal.Background,tv.ColorScheme.HotNormal.Foreground);
  560. TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
  561. // 0
  562. tv.ColorScheme.Normal,
  563. // 1
  564. focused ? invertHotFocus : invertHotNormal});
  565. Application.Shutdown();
  566. }
  567. [Theory]
  568. [InlineData (false)]
  569. [InlineData (true)]
  570. public void TableView_ColorsTest_RowColorGetter (bool focused)
  571. {
  572. var tv = SetUpMiniTable ();
  573. // width exactly matches the max col widths
  574. tv.Bounds = new Rect (0, 0, 5, 4);
  575. var rowHighlight = new ColorScheme () {
  576. Normal = Attribute.Make (Color.BrightCyan, Color.DarkGray),
  577. HotNormal = Attribute.Make (Color.Green, Color.Blue),
  578. HotFocus = Attribute.Make (Color.BrightYellow, Color.White),
  579. Focus = Attribute.Make (Color.Cyan, Color.Magenta),
  580. };
  581. // when B is 2 use the custom highlight colour for the row
  582. tv.Style.RowColorGetter += (e)=>Convert.ToInt32(e.Table.Rows[e.RowIndex][1]) == 2 ? rowHighlight : null;
  583. // private method for forcing the view to be focused/not focused
  584. var setFocusMethod = typeof (View).GetMethod ("SetHasFocus", BindingFlags.Instance | BindingFlags.NonPublic);
  585. // when the view is/isn't focused
  586. setFocusMethod.Invoke (tv, new object [] { focused, tv, true });
  587. tv.Redraw (tv.Bounds);
  588. string expected = @"
  589. ┌─┬─┐
  590. │A│B│
  591. ├─┼─┤
  592. │1│2│
  593. ";
  594. TestHelpers.AssertDriverContentsAre (expected, output);
  595. string expectedColors = @"
  596. 00000
  597. 00000
  598. 00000
  599. 21222
  600. ";
  601. TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
  602. // 0
  603. tv.ColorScheme.Normal,
  604. // 1
  605. focused ? rowHighlight.HotFocus : rowHighlight.HotNormal,
  606. // 2
  607. rowHighlight.Normal});
  608. // change the value in the table so that
  609. // it no longer matches the RowColorGetter
  610. // delegate conditional ( which checks for
  611. // the value 2)
  612. tv.Table.Rows[0][1] = 5;
  613. tv.Redraw (tv.Bounds);
  614. expected = @"
  615. ┌─┬─┐
  616. │A│B│
  617. ├─┼─┤
  618. │1│5│
  619. ";
  620. TestHelpers.AssertDriverContentsAre (expected, output);
  621. expectedColors = @"
  622. 00000
  623. 00000
  624. 00000
  625. 01000
  626. ";
  627. // now we only see 2 colors used (the selected cell color and Normal
  628. // rowHighlight should no longer be used because the delegate returned null
  629. // (now that the cell value is 5 - which does not match the conditional)
  630. TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
  631. // 0
  632. tv.ColorScheme.Normal,
  633. // 1
  634. focused ? tv.ColorScheme.HotFocus : tv.ColorScheme.HotNormal });
  635. // Shutdown must be called to safely clean up Application if Init has been called
  636. Application.Shutdown ();
  637. }
  638. [Theory]
  639. [InlineData (false)]
  640. [InlineData (true)]
  641. public void TableView_ColorsTest_ColorGetter (bool focused)
  642. {
  643. var tv = SetUpMiniTable ();
  644. // width exactly matches the max col widths
  645. tv.Bounds = new Rect (0, 0, 5, 4);
  646. // Create a style for column B
  647. var bStyle = tv.Style.GetOrCreateColumnStyle (tv.Table.Columns ["B"]);
  648. // when B is 2 use the custom highlight colour
  649. var cellHighlight = new ColorScheme () {
  650. Normal = Attribute.Make (Color.BrightCyan, Color.DarkGray),
  651. HotNormal = Attribute.Make (Color.Green, Color.Blue),
  652. HotFocus = Attribute.Make (Color.BrightYellow, Color.White),
  653. Focus = Attribute.Make (Color.Cyan, Color.Magenta),
  654. };
  655. bStyle.ColorGetter = (a) => Convert.ToInt32(a.CellValue) == 2 ? cellHighlight : null;
  656. // private method for forcing the view to be focused/not focused
  657. var setFocusMethod = typeof (View).GetMethod ("SetHasFocus", BindingFlags.Instance | BindingFlags.NonPublic);
  658. // when the view is/isn't focused
  659. setFocusMethod.Invoke (tv, new object [] { focused, tv, true });
  660. tv.Redraw (tv.Bounds);
  661. string expected = @"
  662. ┌─┬─┐
  663. │A│B│
  664. ├─┼─┤
  665. │1│2│
  666. ";
  667. TestHelpers.AssertDriverContentsAre (expected, output);
  668. string expectedColors = @"
  669. 00000
  670. 00000
  671. 00000
  672. 01020
  673. ";
  674. TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
  675. // 0
  676. tv.ColorScheme.Normal,
  677. // 1
  678. focused ? tv.ColorScheme.HotFocus : tv.ColorScheme.HotNormal,
  679. // 2
  680. cellHighlight.Normal});
  681. // change the value in the table so that
  682. // it no longer matches the ColorGetter
  683. // delegate conditional ( which checks for
  684. // the value 2)
  685. tv.Table.Rows[0][1] = 5;
  686. tv.Redraw (tv.Bounds);
  687. expected = @"
  688. ┌─┬─┐
  689. │A│B│
  690. ├─┼─┤
  691. │1│5│
  692. ";
  693. TestHelpers.AssertDriverContentsAre (expected, output);
  694. expectedColors = @"
  695. 00000
  696. 00000
  697. 00000
  698. 01000
  699. ";
  700. // now we only see 2 colors used (the selected cell color and Normal
  701. // cellHighlight should no longer be used because the delegate returned null
  702. // (now that the cell value is 5 - which does not match the conditional)
  703. TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
  704. // 0
  705. tv.ColorScheme.Normal,
  706. // 1
  707. focused ? tv.ColorScheme.HotFocus : tv.ColorScheme.HotNormal });
  708. // Shutdown must be called to safely clean up Application if Init has been called
  709. Application.Shutdown ();
  710. }
  711. private TableView SetUpMiniTable ()
  712. {
  713. var tv = new TableView ();
  714. tv.Bounds = new Rect (0, 0, 10, 4);
  715. var dt = new DataTable ();
  716. var colA = dt.Columns.Add ("A");
  717. var colB = dt.Columns.Add ("B");
  718. dt.Rows.Add (1, 2);
  719. tv.Table = dt;
  720. tv.Style.GetOrCreateColumnStyle (colA).MinWidth = 1;
  721. tv.Style.GetOrCreateColumnStyle (colA).MinWidth = 1;
  722. tv.Style.GetOrCreateColumnStyle (colB).MaxWidth = 1;
  723. tv.Style.GetOrCreateColumnStyle (colB).MaxWidth = 1;
  724. GraphViewTests.InitFakeDriver ();
  725. tv.ColorScheme = Colors.Base;
  726. return tv;
  727. }
  728. [Fact]
  729. [AutoInitShutdown]
  730. public void ScrollDown_OneLineAtATime ()
  731. {
  732. var tableView = new TableView ();
  733. // Set big table
  734. tableView.Table = BuildTable (25, 50);
  735. // 1 header + 4 rows visible
  736. tableView.Bounds = new Rect (0, 0, 25, 5);
  737. tableView.Style.ShowHorizontalHeaderUnderline = false;
  738. tableView.Style.ShowHorizontalHeaderOverline = false;
  739. tableView.Style.AlwaysShowHeaders = true;
  740. // select last row
  741. tableView.SelectedRow = 3; // row is 0 indexed so this is the 4th visible row
  742. // Scroll down
  743. tableView.ProcessKey (new KeyEvent () { Key = Key.CursorDown });
  744. // Scrolled off the page by 1 row so it should only have moved down 1 line of RowOffset
  745. Assert.Equal(4,tableView.SelectedRow);
  746. Assert.Equal (1, tableView.RowOffset);
  747. }
  748. [Fact]
  749. public void ScrollRight_SmoothScrolling ()
  750. {
  751. GraphViewTests.InitFakeDriver ();
  752. var tableView = new TableView ();
  753. tableView.ColorScheme = Colors.TopLevel;
  754. // 3 columns are visibile
  755. tableView.Bounds = new Rect (0, 0, 7, 5);
  756. tableView.Style.ShowHorizontalHeaderUnderline = false;
  757. tableView.Style.ShowHorizontalHeaderOverline = false;
  758. tableView.Style.AlwaysShowHeaders = true;
  759. tableView.Style.SmoothHorizontalScrolling = true;
  760. var dt = new DataTable ();
  761. dt.Columns.Add ("A");
  762. dt.Columns.Add ("B");
  763. dt.Columns.Add ("C");
  764. dt.Columns.Add ("D");
  765. dt.Columns.Add ("E");
  766. dt.Columns.Add ("F");
  767. dt.Rows.Add (1, 2, 3, 4, 5, 6);
  768. tableView.Table = dt;
  769. // select last visible column
  770. tableView.SelectedColumn = 2; // column C
  771. tableView.Redraw (tableView.Bounds);
  772. string expected =
  773. @"
  774. │A│B│C│
  775. │1│2│3│";
  776. TestHelpers.AssertDriverContentsAre (expected, output);
  777. // Scroll right
  778. tableView.ProcessKey (new KeyEvent () { Key = Key.CursorRight });
  779. tableView.Redraw (tableView.Bounds);
  780. // Note that with SmoothHorizontalScrolling only a single new column
  781. // is exposed when scrolling right. This is not always the case though
  782. // sometimes if the leftmost column is long (i.e. A is a long column)
  783. // then when A is pushed off the screen multiple new columns could be exposed
  784. // (not just D but also E and F). This is because TableView never shows
  785. // 'half cells' or scrolls by console unit (scrolling is done by table row/column increments).
  786. expected =
  787. @"
  788. │B│C│D│
  789. │2│3│4│";
  790. TestHelpers.AssertDriverContentsAre (expected, output);
  791. // Shutdown must be called to safely clean up Application if Init has been called
  792. Application.Shutdown ();
  793. }
  794. [Fact]
  795. public void ScrollRight_WithoutSmoothScrolling ()
  796. {
  797. GraphViewTests.InitFakeDriver ();
  798. var tableView = new TableView ();
  799. tableView.ColorScheme = Colors.TopLevel;
  800. // 3 columns are visibile
  801. tableView.Bounds = new Rect (0, 0, 7, 5);
  802. tableView.Style.ShowHorizontalHeaderUnderline = false;
  803. tableView.Style.ShowHorizontalHeaderOverline = false;
  804. tableView.Style.AlwaysShowHeaders = true;
  805. tableView.Style.SmoothHorizontalScrolling = false;
  806. var dt = new DataTable ();
  807. dt.Columns.Add ("A");
  808. dt.Columns.Add ("B");
  809. dt.Columns.Add ("C");
  810. dt.Columns.Add ("D");
  811. dt.Columns.Add ("E");
  812. dt.Columns.Add ("F");
  813. dt.Rows.Add (1, 2, 3, 4, 5, 6);
  814. tableView.Table = dt;
  815. // select last visible column
  816. tableView.SelectedColumn = 2; // column C
  817. tableView.Redraw (tableView.Bounds);
  818. string expected =
  819. @"
  820. │A│B│C│
  821. │1│2│3│";
  822. TestHelpers.AssertDriverContentsAre (expected, output);
  823. // Scroll right
  824. tableView.ProcessKey (new KeyEvent () { Key = Key.CursorRight });
  825. tableView.Redraw (tableView.Bounds);
  826. // notice that without smooth scrolling we just update the first column
  827. // rendered in the table to the newly exposed column (D). This is fast
  828. // since we don't have to worry about repeatedly measuring the content
  829. // area as we scroll until the new column (D) is exposed. But it makes
  830. // the view 'jump' to expose all new columns
  831. expected =
  832. @"
  833. │D│E│F│
  834. │4│5│6│";
  835. TestHelpers.AssertDriverContentsAre (expected, output);
  836. // Shutdown must be called to safely clean up Application if Init has been called
  837. Application.Shutdown ();
  838. }
  839. private TableView GetABCDEFTableView (out DataTable dt)
  840. {
  841. var tableView = new TableView ();
  842. tableView.ColorScheme = Colors.TopLevel;
  843. // 3 columns are visible
  844. tableView.Bounds = new Rect (0, 0, 7, 5);
  845. tableView.Style.ShowHorizontalHeaderUnderline = false;
  846. tableView.Style.ShowHorizontalHeaderOverline = false;
  847. tableView.Style.AlwaysShowHeaders = true;
  848. tableView.Style.SmoothHorizontalScrolling = false;
  849. dt = new DataTable ();
  850. dt.Columns.Add ("A");
  851. dt.Columns.Add ("B");
  852. dt.Columns.Add ("C");
  853. dt.Columns.Add ("D");
  854. dt.Columns.Add ("E");
  855. dt.Columns.Add ("F");
  856. dt.Rows.Add (1, 2, 3, 4, 5, 6);
  857. tableView.Table = dt;
  858. return tableView;
  859. }
  860. [Fact, AutoInitShutdown]
  861. public void TestColumnStyle_VisibleFalse_IsNotRendered()
  862. {
  863. var tableView = GetABCDEFTableView (out DataTable dt);
  864. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["B"]).Visible = false;
  865. tableView.Redraw (tableView.Bounds);
  866. string expected =
  867. @"
  868. │A│C│D│
  869. │1│3│4│";
  870. TestHelpers.AssertDriverContentsAre (expected, output);
  871. }
  872. [Fact, AutoInitShutdown]
  873. public void TestColumnStyle_FirstColumnVisibleFalse_IsNotRendered ()
  874. {
  875. var tableView = GetABCDEFTableView (out DataTable dt);
  876. tableView.Style.ShowHorizontalScrollIndicators = true;
  877. tableView.Style.ShowHorizontalHeaderUnderline = true;
  878. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["A"]).Visible = false;
  879. tableView.Redraw (tableView.Bounds);
  880. string expected =
  881. @"
  882. │B│C│D│
  883. ├─┼─┼─►
  884. │2│3│4│";
  885. TestHelpers.AssertDriverContentsAre (expected, output);
  886. }
  887. [Fact, AutoInitShutdown]
  888. public void TestColumnStyle_AllColumnsVisibleFalse_BehavesAsTableNull ()
  889. {
  890. var tableView = GetABCDEFTableView (out DataTable dt);
  891. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["A"]).Visible = false;
  892. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["B"]).Visible = false;
  893. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["C"]).Visible = false;
  894. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["D"]).Visible = false;
  895. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["E"]).Visible = false;
  896. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["F"]).Visible = false;
  897. // expect nothing to be rendered when all columns are invisible
  898. string expected =
  899. @"
  900. ";
  901. tableView.Redraw (tableView.Bounds);
  902. TestHelpers.AssertDriverContentsAre (expected, output);
  903. // expect behavior to match when Table is null
  904. tableView.Table = null;
  905. tableView.Redraw (tableView.Bounds);
  906. TestHelpers.AssertDriverContentsAre (expected, output);
  907. }
  908. [Fact, AutoInitShutdown]
  909. public void TestColumnStyle_RemainingColumnsInvisible_NoScrollIndicator ()
  910. {
  911. var tableView = GetABCDEFTableView (out DataTable dt);
  912. tableView.Style.ShowHorizontalScrollIndicators = true;
  913. tableView.Style.ShowHorizontalHeaderUnderline = true;
  914. tableView.Redraw (tableView.Bounds);
  915. // normally we should have scroll indicators because DEF are of screen
  916. string expected =
  917. @"
  918. │A│B│C│
  919. ├─┼─┼─►
  920. │1│2│3│";
  921. TestHelpers.AssertDriverContentsAre (expected, output);
  922. // but if DEF are invisible we shouldn't be showing the indicator
  923. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["D"]).Visible = false;
  924. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["E"]).Visible = false;
  925. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["F"]).Visible = false;
  926. expected =
  927. @"
  928. │A│B│C│
  929. ├─┼─┼─┤
  930. │1│2│3│";
  931. tableView.Redraw (tableView.Bounds);
  932. TestHelpers.AssertDriverContentsAre (expected, output);
  933. }
  934. [Fact, AutoInitShutdown]
  935. public void TestColumnStyle_PreceedingColumnsInvisible_NoScrollIndicator ()
  936. {
  937. var tableView = GetABCDEFTableView (out DataTable dt);
  938. tableView.Style.ShowHorizontalScrollIndicators = true;
  939. tableView.Style.ShowHorizontalHeaderUnderline = true;
  940. tableView.ColumnOffset = 1;
  941. tableView.Redraw (tableView.Bounds);
  942. // normally we should have scroll indicators because A,E and F are of screen
  943. string expected =
  944. @"
  945. │B│C│D│
  946. ◄─┼─┼─►
  947. │2│3│4│";
  948. TestHelpers.AssertDriverContentsAre (expected, output);
  949. // but if E and F are invisible so we shouldn't show right
  950. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["E"]).Visible = false;
  951. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["F"]).Visible = false;
  952. expected =
  953. @"
  954. │B│C│D│
  955. ◄─┼─┼─┤
  956. │2│3│4│";
  957. tableView.Redraw (tableView.Bounds);
  958. TestHelpers.AssertDriverContentsAre (expected, output);
  959. // now also A is invisible so we cannot scroll in either direction
  960. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["A"]).Visible = false;
  961. expected =
  962. @"
  963. │B│C│D│
  964. ├─┼─┼─┤
  965. │2│3│4│";
  966. tableView.Redraw (tableView.Bounds);
  967. TestHelpers.AssertDriverContentsAre (expected, output);
  968. }
  969. [Fact, AutoInitShutdown]
  970. public void TestColumnStyle_VisibleFalse_CursorStepsOverInvisibleColumns ()
  971. {
  972. var tableView = GetABCDEFTableView (out var dt);
  973. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["B"]).Visible = false;
  974. tableView.SelectedColumn = 0;
  975. tableView.ProcessKey (new KeyEvent { Key = Key.CursorRight });
  976. // Expect the cursor navigation to skip over the invisible column(s)
  977. Assert.Equal(2,tableView.SelectedColumn);
  978. tableView.ProcessKey (new KeyEvent { Key = Key.CursorLeft });
  979. // Expect the cursor navigation backwards to skip over invisible column too
  980. Assert.Equal (0, tableView.SelectedColumn);
  981. }
  982. [InlineData(true)]
  983. [InlineData (false)]
  984. [Theory, AutoInitShutdown]
  985. public void TestColumnStyle_FirstColumnVisibleFalse_CursorStaysAt1(bool useHome)
  986. {
  987. var tableView = GetABCDEFTableView (out var dt);
  988. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["A"]).Visible = false;
  989. tableView.SelectedColumn = 0;
  990. Assert.Equal (0, tableView.SelectedColumn);
  991. // column 0 is invisible so this method should move to 1
  992. tableView.EnsureValidSelection();
  993. Assert.Equal (1, tableView.SelectedColumn);
  994. tableView.ProcessKey (new KeyEvent
  995. {
  996. Key = useHome ? Key.Home : Key.CursorLeft
  997. });
  998. // Expect the cursor to stay at 1
  999. Assert.Equal (1, tableView.SelectedColumn);
  1000. }
  1001. [InlineData(true)]
  1002. [InlineData (false)]
  1003. [Theory, AutoInitShutdown]
  1004. public void TestMoveStartEnd_WithFullRowSelect(bool withFullRowSelect)
  1005. {
  1006. var tableView = GetTwoRowSixColumnTable ();
  1007. tableView.FullRowSelect = withFullRowSelect;
  1008. tableView.SelectedRow = 1;
  1009. tableView.SelectedColumn = 1;
  1010. tableView.ProcessKey (new KeyEvent
  1011. {
  1012. Key = Key.Home | Key.CtrlMask
  1013. });
  1014. if(withFullRowSelect)
  1015. {
  1016. // Should not be any horizontal movement when
  1017. // using navigate to Start/End and FullRowSelect
  1018. Assert.Equal (1, tableView.SelectedColumn);
  1019. Assert.Equal (0, tableView.SelectedRow);
  1020. }
  1021. else
  1022. {
  1023. Assert.Equal (0, tableView.SelectedColumn);
  1024. Assert.Equal (0, tableView.SelectedRow);
  1025. }
  1026. tableView.ProcessKey (new KeyEvent
  1027. {
  1028. Key = Key.End | Key.CtrlMask
  1029. });
  1030. if(withFullRowSelect)
  1031. {
  1032. Assert.Equal (1, tableView.SelectedColumn);
  1033. Assert.Equal (1, tableView.SelectedRow);
  1034. }
  1035. else
  1036. {
  1037. Assert.Equal (5, tableView.SelectedColumn);
  1038. Assert.Equal (1, tableView.SelectedRow);
  1039. }
  1040. }
  1041. [InlineData (true)]
  1042. [InlineData (false)]
  1043. [Theory, AutoInitShutdown]
  1044. public void TestColumnStyle_LastColumnVisibleFalse_CursorStaysAt2 (bool useEnd)
  1045. {
  1046. var tableView = GetABCDEFTableView (out var dt);
  1047. // select D
  1048. tableView.SelectedColumn = 3;
  1049. Assert.Equal (3, tableView.SelectedColumn);
  1050. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["D"]).Visible = false;
  1051. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["E"]).Visible = false;
  1052. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["F"]).Visible = false;
  1053. // column D is invisible so this method should move to 2 (C)
  1054. tableView.EnsureValidSelection ();
  1055. Assert.Equal (2, tableView.SelectedColumn);
  1056. tableView.ProcessKey (new KeyEvent {
  1057. Key = useEnd ? Key.End : Key.CursorRight
  1058. });
  1059. // Expect the cursor to stay at 2
  1060. Assert.Equal (2, tableView.SelectedColumn);
  1061. }
  1062. [Fact, AutoInitShutdown]
  1063. public void TestColumnStyle_VisibleFalse_MultiSelected ()
  1064. {
  1065. var tableView = GetABCDEFTableView (out var dt);
  1066. // user has rectangular selection
  1067. tableView.MultiSelectedRegions.Push (
  1068. new TableView.TableSelection(
  1069. new Point(0,0),
  1070. new Rect(0, 0, 3, 1))
  1071. );
  1072. Assert.Equal (3, tableView.GetAllSelectedCells ().Count());
  1073. Assert.True (tableView.IsSelected (0, 0));
  1074. Assert.True (tableView.IsSelected (1, 0));
  1075. Assert.True (tableView.IsSelected (2, 0));
  1076. Assert.False (tableView.IsSelected (3, 0));
  1077. // if middle column is invisible
  1078. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["B"]).Visible = false;
  1079. // it should not be included in the selection
  1080. Assert.Equal (2, tableView.GetAllSelectedCells ().Count ());
  1081. Assert.True (tableView.IsSelected (0, 0));
  1082. Assert.False (tableView.IsSelected (1, 0));
  1083. Assert.True (tableView.IsSelected (2, 0));
  1084. Assert.False (tableView.IsSelected (3, 0));
  1085. Assert.DoesNotContain(new Point(1,0),tableView.GetAllSelectedCells ());
  1086. }
  1087. [Fact, AutoInitShutdown]
  1088. public void TestColumnStyle_VisibleFalse_MultiSelectingStepsOverInvisibleColumns ()
  1089. {
  1090. var tableView = GetABCDEFTableView (out var dt);
  1091. // if middle column is invisible
  1092. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["B"]).Visible = false;
  1093. tableView.ProcessKey (new KeyEvent { Key = Key.CursorRight | Key.ShiftMask });
  1094. // Selection should extend from A to C but skip B
  1095. Assert.Equal (2, tableView.GetAllSelectedCells ().Count ());
  1096. Assert.True (tableView.IsSelected (0, 0));
  1097. Assert.False (tableView.IsSelected (1, 0));
  1098. Assert.True (tableView.IsSelected (2, 0));
  1099. Assert.False (tableView.IsSelected (3, 0));
  1100. Assert.DoesNotContain (new Point (1, 0), tableView.GetAllSelectedCells ());
  1101. }
  1102. [Theory, AutoInitShutdown]
  1103. [InlineData(new object[] { true,true })]
  1104. [InlineData (new object[] { false,true })]
  1105. [InlineData (new object [] { true, false})]
  1106. [InlineData (new object [] { false, false})]
  1107. public void TestColumnStyle_VisibleFalse_DoesNotEffect_EnsureSelectedCellIsVisible (bool smooth, bool invisibleCol)
  1108. {
  1109. var tableView = GetABCDEFTableView (out var dt);
  1110. tableView.Style.SmoothHorizontalScrolling = smooth;
  1111. if(invisibleCol) {
  1112. tableView.Style.GetOrCreateColumnStyle (dt.Columns ["D"]).Visible = false;
  1113. }
  1114. // New TableView should have first cell selected
  1115. Assert.Equal (0,tableView.SelectedColumn);
  1116. // With no scrolling
  1117. Assert.Equal (0, tableView.ColumnOffset);
  1118. // A,B and C are visible on screen at the moment so these should have no effect
  1119. tableView.SelectedColumn = 1;
  1120. tableView.EnsureSelectedCellIsVisible ();
  1121. Assert.Equal (0, tableView.ColumnOffset);
  1122. tableView.SelectedColumn = 2;
  1123. tableView.EnsureSelectedCellIsVisible ();
  1124. Assert.Equal (0, tableView.ColumnOffset);
  1125. // Selecting D should move the visible table area to fit D onto the screen
  1126. tableView.SelectedColumn = 3;
  1127. tableView.EnsureSelectedCellIsVisible ();
  1128. Assert.Equal (smooth ? 1 : 3, tableView.ColumnOffset);
  1129. }
  1130. [Fact]
  1131. public void LongColumnTest ()
  1132. {
  1133. GraphViewTests.InitFakeDriver ();
  1134. var tableView = new TableView ();
  1135. tableView.ColorScheme = Colors.TopLevel;
  1136. // 25 characters can be printed into table
  1137. tableView.Bounds = new Rect (0, 0, 25, 5);
  1138. tableView.Style.ShowHorizontalHeaderUnderline = true;
  1139. tableView.Style.ShowHorizontalHeaderOverline = false;
  1140. tableView.Style.AlwaysShowHeaders = true;
  1141. tableView.Style.SmoothHorizontalScrolling = true;
  1142. var dt = new DataTable ();
  1143. dt.Columns.Add ("A");
  1144. dt.Columns.Add ("B");
  1145. dt.Columns.Add ("Very Long Column");
  1146. dt.Rows.Add (1, 2, new string('a',500));
  1147. dt.Rows.Add (1, 2, "aaa");
  1148. tableView.Table = dt;
  1149. tableView.Redraw (tableView.Bounds);
  1150. // default behaviour of TableView is not to render
  1151. // columns unless there is sufficient space
  1152. string expected =
  1153. @"
  1154. │A│B │
  1155. ├─┼─────────────────────►
  1156. │1│2 │
  1157. │1│2 │
  1158. ";
  1159. TestHelpers.AssertDriverContentsAre (expected, output);
  1160. // get a style for the long column
  1161. var style = tableView.Style.GetOrCreateColumnStyle(dt.Columns[2]);
  1162. // one way the API user can fix this for long columns
  1163. // is to specify a max width for the column
  1164. style.MaxWidth = 10;
  1165. tableView.Redraw (tableView.Bounds);
  1166. expected =
  1167. @"
  1168. │A│B│Very Long │
  1169. ├─┼─┼───────────────────┤
  1170. │1│2│aaaaaaaaaa │
  1171. │1│2│aaa │
  1172. ";
  1173. TestHelpers.AssertDriverContentsAre (expected, output);
  1174. // revert the style change
  1175. style.MaxWidth = TableView.DefaultMaxCellWidth;
  1176. // another way API user can fix problem is to implement
  1177. // RepresentationGetter and apply max length there
  1178. style.RepresentationGetter = (s)=>{
  1179. return s.ToString().Length < 15 ? s.ToString() : s.ToString().Substring(0,13)+"...";
  1180. };
  1181. tableView.Redraw (tableView.Bounds);
  1182. expected =
  1183. @"
  1184. │A│B│Very Long Column │
  1185. ├─┼─┼───────────────────┤
  1186. │1│2│aaaaaaaaaaaaa... │
  1187. │1│2│aaa │
  1188. ";
  1189. TestHelpers.AssertDriverContentsAre (expected, output);
  1190. // revert style change
  1191. style.RepresentationGetter = null;
  1192. // Both of the above methods rely on having a fixed
  1193. // size limit for the column. These are awkward if a
  1194. // table is resizeable e.g. Dim.Fill(). Ideally we want
  1195. // to render in any space available and truncate the content
  1196. // of the column dynamically so it fills the free space at
  1197. // the end of the table.
  1198. // We can now specify that the column can be any length
  1199. // (Up to MaxWidth) but the renderer can accept using
  1200. // less space down to this limit
  1201. style.MinAcceptableWidth = 5;
  1202. tableView.Redraw (tableView.Bounds);
  1203. expected =
  1204. @"
  1205. │A│B│Very Long Column │
  1206. ├─┼─┼───────────────────┤
  1207. │1│2│aaaaaaaaaaaaaaaaaaa│
  1208. │1│2│aaa │
  1209. ";
  1210. TestHelpers.AssertDriverContentsAre (expected, output);
  1211. // Now test making the width too small for the MinAcceptableWidth
  1212. // the Column won't fit so should not be rendered
  1213. Application.Shutdown ();
  1214. GraphViewTests.InitFakeDriver ();
  1215. tableView.Bounds = new Rect(0,0,9,5);
  1216. tableView.Redraw (tableView.Bounds);
  1217. expected =
  1218. @"
  1219. │A│B │
  1220. ├─┼─────►
  1221. │1│2 │
  1222. │1│2 │
  1223. ";
  1224. TestHelpers.AssertDriverContentsAre (expected, output);
  1225. // setting width to 10 leaves just enough space for the column to
  1226. // meet MinAcceptableWidth of 5. Column width includes terminator line
  1227. // symbol (e.g. ┤ or │)
  1228. tableView.Bounds = new Rect (0, 0, 10, 5);
  1229. tableView.Redraw (tableView.Bounds);
  1230. expected =
  1231. @"
  1232. │A│B│Very│
  1233. ├─┼─┼────┤
  1234. │1│2│aaaa│
  1235. │1│2│aaa │
  1236. ";
  1237. TestHelpers.AssertDriverContentsAre (expected, output);
  1238. Application.Shutdown ();
  1239. }
  1240. [Fact]
  1241. public void ScrollIndicators ()
  1242. {
  1243. GraphViewTests.InitFakeDriver ();
  1244. var tableView = new TableView ();
  1245. tableView.ColorScheme = Colors.TopLevel;
  1246. // 3 columns are visibile
  1247. tableView.Bounds = new Rect (0, 0, 7, 5);
  1248. tableView.Style.ShowHorizontalHeaderUnderline = true;
  1249. tableView.Style.ShowHorizontalHeaderOverline = false;
  1250. tableView.Style.AlwaysShowHeaders = true;
  1251. tableView.Style.SmoothHorizontalScrolling = true;
  1252. var dt = new DataTable ();
  1253. dt.Columns.Add ("A");
  1254. dt.Columns.Add ("B");
  1255. dt.Columns.Add ("C");
  1256. dt.Columns.Add ("D");
  1257. dt.Columns.Add ("E");
  1258. dt.Columns.Add ("F");
  1259. dt.Rows.Add (1, 2, 3, 4, 5, 6);
  1260. tableView.Table = dt;
  1261. // select last visible column
  1262. tableView.SelectedColumn = 2; // column C
  1263. tableView.Redraw (tableView.Bounds);
  1264. // user can only scroll right so sees right indicator
  1265. // Because first column in table is A
  1266. string expected =
  1267. @"
  1268. │A│B│C│
  1269. ├─┼─┼─►
  1270. │1│2│3│";
  1271. TestHelpers.AssertDriverContentsAre (expected, output);
  1272. // Scroll right
  1273. tableView.ProcessKey (new KeyEvent () { Key = Key.CursorRight });
  1274. // since A is now pushed off screen we get indicator showing
  1275. // that user can scroll left to see first column
  1276. tableView.Redraw (tableView.Bounds);
  1277. expected =
  1278. @"
  1279. │B│C│D│
  1280. ◄─┼─┼─►
  1281. │2│3│4│";
  1282. TestHelpers.AssertDriverContentsAre (expected, output);
  1283. // Scroll right twice more (to end of columns)
  1284. tableView.ProcessKey (new KeyEvent () { Key = Key.CursorRight });
  1285. tableView.ProcessKey (new KeyEvent () { Key = Key.CursorRight });
  1286. tableView.Redraw (tableView.Bounds);
  1287. expected =
  1288. @"
  1289. │D│E│F│
  1290. ◄─┼─┼─┤
  1291. │4│5│6│";
  1292. TestHelpers.AssertDriverContentsAre (expected, output);
  1293. // Shutdown must be called to safely clean up Application if Init has been called
  1294. Application.Shutdown ();
  1295. }
  1296. /// <summary>
  1297. /// Builds a simple table of string columns with the requested number of columns and rows
  1298. /// </summary>
  1299. /// <param name="cols"></param>
  1300. /// <param name="rows"></param>
  1301. /// <returns></returns>
  1302. public static DataTable BuildTable (int cols, int rows)
  1303. {
  1304. var dt = new DataTable ();
  1305. for (int c = 0; c < cols; c++) {
  1306. dt.Columns.Add ("Col" + c);
  1307. }
  1308. for (int r = 0; r < rows; r++) {
  1309. var newRow = dt.NewRow ();
  1310. for (int c = 0; c < cols; c++) {
  1311. newRow [c] = $"R{r}C{c}";
  1312. }
  1313. dt.Rows.Add (newRow);
  1314. }
  1315. return dt;
  1316. }
  1317. [Fact, AutoInitShutdown]
  1318. public void Test_ScreenToCell ()
  1319. {
  1320. var tableView = GetTwoRowSixColumnTable ();
  1321. tableView.Redraw (tableView.Bounds);
  1322. // user can only scroll right so sees right indicator
  1323. // Because first column in table is A
  1324. string expected =
  1325. @"
  1326. │A│B│C│
  1327. ├─┼─┼─►
  1328. │1│2│3│
  1329. │1│2│3│";
  1330. TestHelpers.AssertDriverContentsAre (expected, output);
  1331. // ---------------- X=0 -----------------------
  1332. // click is before first cell
  1333. Assert.Null (tableView.ScreenToCell (0, 0));
  1334. Assert.Null (tableView.ScreenToCell (0, 1));
  1335. Assert.Null (tableView.ScreenToCell (0, 2));
  1336. Assert.Null (tableView.ScreenToCell (0, 3));
  1337. Assert.Null (tableView.ScreenToCell (0, 4));
  1338. // ---------------- X=1 -----------------------
  1339. // click in header
  1340. Assert.Null (tableView.ScreenToCell (1, 0));
  1341. // click in header row line
  1342. Assert.Null (tableView.ScreenToCell (1, 1));
  1343. // click in cell 0,0
  1344. Assert.Equal (new Point(0,0),tableView.ScreenToCell (1, 2));
  1345. // click in cell 0,1
  1346. Assert.Equal (new Point (0, 1), tableView.ScreenToCell (1, 3));
  1347. // after last row
  1348. Assert.Null (tableView.ScreenToCell (1, 4));
  1349. // ---------------- X=2 -----------------------
  1350. // ( even though there is a horizontal dividing line here we treat it as a hit on the cell before)
  1351. // click in header
  1352. Assert.Null (tableView.ScreenToCell (2, 0));
  1353. // click in header row line
  1354. Assert.Null (tableView.ScreenToCell (2, 1));
  1355. // click in cell 0,0
  1356. Assert.Equal (new Point (0, 0), tableView.ScreenToCell (2, 2));
  1357. // click in cell 0,1
  1358. Assert.Equal (new Point (0, 1), tableView.ScreenToCell (2, 3));
  1359. // after last row
  1360. Assert.Null (tableView.ScreenToCell (2, 4));
  1361. // ---------------- X=3 -----------------------
  1362. // click in header
  1363. Assert.Null (tableView.ScreenToCell (3, 0));
  1364. // click in header row line
  1365. Assert.Null (tableView.ScreenToCell (3, 1));
  1366. // click in cell 1,0
  1367. Assert.Equal (new Point (1, 0), tableView.ScreenToCell (3, 2));
  1368. // click in cell 1,1
  1369. Assert.Equal (new Point (1, 1), tableView.ScreenToCell (3, 3));
  1370. // after last row
  1371. Assert.Null (tableView.ScreenToCell (3, 4));
  1372. }
  1373. [Fact, AutoInitShutdown]
  1374. public void Test_ScreenToCell_DataColumnOverload ()
  1375. {
  1376. var tableView = GetTwoRowSixColumnTable ();
  1377. tableView.Redraw (tableView.Bounds);
  1378. // user can only scroll right so sees right indicator
  1379. // Because first column in table is A
  1380. string expected =
  1381. @"
  1382. │A│B│C│
  1383. ├─┼─┼─►
  1384. │1│2│3│
  1385. │1│2│3│";
  1386. TestHelpers.AssertDriverContentsAre (expected, output);
  1387. DataColumn col;
  1388. // ---------------- X=0 -----------------------
  1389. // click is before first cell
  1390. Assert.Null (tableView.ScreenToCell (0, 0,out col));
  1391. Assert.Null (col);
  1392. Assert.Null (tableView.ScreenToCell (0, 1,out col));
  1393. Assert.Null (col);
  1394. Assert.Null (tableView.ScreenToCell (0, 2,out col));
  1395. Assert.Null (col);
  1396. Assert.Null (tableView.ScreenToCell (0, 3,out col));
  1397. Assert.Null (col);
  1398. Assert.Null (tableView.ScreenToCell (0, 4,out col));
  1399. Assert.Null (col);
  1400. // ---------------- X=1 -----------------------
  1401. // click in header
  1402. Assert.Null (tableView.ScreenToCell (1, 0, out col));
  1403. Assert.Equal ("A", col.ColumnName);
  1404. // click in header row line (click in the horizontal line below header counts as click in header above - consistent with the column hit box)
  1405. Assert.Null (tableView.ScreenToCell (1, 1, out col));
  1406. Assert.Equal ("A", col.ColumnName);
  1407. // click in cell 0,0
  1408. Assert.Equal (new Point (0, 0), tableView.ScreenToCell (1, 2, out col));
  1409. Assert.Null (col);
  1410. // click in cell 0,1
  1411. Assert.Equal (new Point (0, 1), tableView.ScreenToCell (1, 3, out col));
  1412. Assert.Null (col);
  1413. // after last row
  1414. Assert.Null (tableView.ScreenToCell (1, 4, out col));
  1415. Assert.Null (col);
  1416. // ---------------- X=2 -----------------------
  1417. // click in header
  1418. Assert.Null (tableView.ScreenToCell (2, 0, out col));
  1419. Assert.Equal ("A", col.ColumnName);
  1420. // click in header row line
  1421. Assert.Null (tableView.ScreenToCell (2, 1, out col));
  1422. Assert.Equal ("A", col.ColumnName);
  1423. // click in cell 0,0
  1424. Assert.Equal (new Point (0, 0), tableView.ScreenToCell (2, 2, out col));
  1425. Assert.Null (col);
  1426. // click in cell 0,1
  1427. Assert.Equal (new Point (0, 1), tableView.ScreenToCell (2, 3, out col));
  1428. Assert.Null (col);
  1429. // after last row
  1430. Assert.Null (tableView.ScreenToCell (2, 4, out col));
  1431. Assert.Null (col);
  1432. // ---------------- X=3 -----------------------
  1433. // click in header
  1434. Assert.Null (tableView.ScreenToCell (3, 0, out col));
  1435. Assert.Equal ("B", col.ColumnName);
  1436. // click in header row line
  1437. Assert.Null (tableView.ScreenToCell (3, 1, out col));
  1438. Assert.Equal ("B", col.ColumnName);
  1439. // click in cell 1,0
  1440. Assert.Equal (new Point (1, 0), tableView.ScreenToCell (3, 2, out col));
  1441. Assert.Null (col);
  1442. // click in cell 1,1
  1443. Assert.Equal (new Point (1, 1), tableView.ScreenToCell (3, 3, out col));
  1444. Assert.Null (col);
  1445. // after last row
  1446. Assert.Null (tableView.ScreenToCell (3, 4, out col));
  1447. Assert.Null (col);
  1448. }
  1449. private TableView GetTwoRowSixColumnTable ()
  1450. {
  1451. var tableView = new TableView ();
  1452. tableView.ColorScheme = Colors.TopLevel;
  1453. // 3 columns are visible
  1454. tableView.Bounds = new Rect (0, 0, 7, 5);
  1455. tableView.Style.ShowHorizontalHeaderUnderline = true;
  1456. tableView.Style.ShowHorizontalHeaderOverline = false;
  1457. tableView.Style.AlwaysShowHeaders = true;
  1458. tableView.Style.SmoothHorizontalScrolling = true;
  1459. var dt = new DataTable ();
  1460. dt.Columns.Add ("A");
  1461. dt.Columns.Add ("B");
  1462. dt.Columns.Add ("C");
  1463. dt.Columns.Add ("D");
  1464. dt.Columns.Add ("E");
  1465. dt.Columns.Add ("F");
  1466. dt.Rows.Add (1, 2, 3, 4, 5, 6);
  1467. dt.Rows.Add (1, 2, 3, 4, 5, 6);
  1468. tableView.Table = dt;
  1469. return tableView;
  1470. }
  1471. }
  1472. }