Skip to content

TableView - keep selection #2335

Answered by tznind
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

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.

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());

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant