-
I'm looking for any suggestion on how to keep the full-row selection of a table-view as rows are added to it from another thread. Current behavior is the new row added to the table becomes selected. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you are simply adding rows to the table then the current selection will not change. Here is some example code and a gif that shows its behaviour. Make sure you use using System.Data;
using Terminal.Gui;
Application.Init();
var w = new Window();
var rand = new Random();
var dt = new DataTable();
dt.Columns.Add("Col1");
dt.Rows.Add(rand.Next());
var tv = new TableView()
{
Width = Dim.Fill(),
Height = Dim.Fill(),
Table = dt,
FullRowSelect = true,
};
Task.Run(async ()=>
{
while(true)
{
await Task.Delay(2000);
Application.MainLoop.Invoke(()=>
{
dt.Rows.Add(rand.Next());
tv.Update();
});
}
});
w.Add(tv);
Application.Run(w);
Application.Shutdown(); That said you can still change the var currentRow = tv.SelectedRow;
// Do something
tv.SelectedRow = currentRow; If you are inserting the row at the top of the table you can just adjust var row = dt.NewRow();
row[0] = rand.Next();
dt.Rows.InsertAt(row,0);
tv.Update();
// because we are inserting at beginning we need
// to shift selection down
tv.SelectedRow++; |
Beta Was this translation helpful? Give feedback.
If you are simply adding rows to the table then the current selection will not change. Here is some example code and a gif that shows its behaviour. Make sure you use
Application.MainLoop.Invoke
as in the code below.