question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How do I add to a ListView after the ListWrapper has been initilized?

See original GitHub issue

I have a use case where I would like to update the underlying datasource for my ListView. I was hoping I could simply .Add() or .Remove() from the underlying IList datasource but that doesn’t seem to be the case. Is my only option to set the ListView.Source property with a new IList?

Example

private static List<string> source1 = new List<string>() { "Header" };

public static void Main()
{
    Application.Init();
    
    var window = new Window() { Height = Dim.Fill() ,Width = Dim.Fill() };
    Application.Top.Add(window);

    var list1 = new ListView(source1) { Width = 8, Height = Dim.Fill() };
    window.Add(list1);

    var index = 1;
    Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(1), loop =>
    {
        source1.Add($"Item {index++}"); // These are not rendered
        return true;
    });

    Application.Run();
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
brian-pickenscommented, Jul 31, 2020

Thanks @BDisp for an attempted workaround. However I was hoping I could essentially use an expression as my IList source. To answer my own question, I realized that using a Property accessor actually calls the Get method and thus returns a temporary value. It is not a reference to the dictionary source. Here is the stackoverflow question I found talking about it.

I think what I’ll do is create my own implementation of IListDatasource that takes an Expression and see if that will work for my use case.

1reaction
tigcommented, Jul 30, 2020

list1.MoveDown (); automatically call the SetNeedsDisplay

This will work too, but will cause the list to scroll as things are added. That is not always wanted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Question: How do I add to a ListView after the ListWrapper ...
Question : How do I add to a ListView after the ListWrapper has been initilized? #834 ... Init(); var window = new Window()...
Read more >
c# - Initializing ListView, why can't I do this?
This will create a List (an expandable collection); create a new ListViewItem in a loop, give that ListViewItem the text you want it...
Read more >
Release notes - @pnp/spfx-controls-react
Fix for the ListView control when selection is used in combination with setState . Beta 1.0.0-beta.7¶. New control(s)¶. Grouping functionality added to the ......
Read more >
Index (server-common-api)
Returns a token when an action is initialized If there is a custom callback, there needs to be a custom layout to render...
Read more >
Issue with ObservableCollection in .net MAUI
When I open the app it reads the sqlite database and populates the ListView however when I add a new entry to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found