Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add items to ListView with .NET C#

I want to add items to a ListView with .NET 7 + C#. Is there a way to do this programmatically with C#? The reason is the app will receive data from a server and I want to add parts of the data to the listview.

I have read this https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/listview?view=net-maui-7.0
but there is no information on how to do this with C# completely, neither is there anything I can find on Google (except by installing packages, which I want to avoid). Maybe I am misunderstanding something.

I would appreciate an example.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

the ListView gets its data from its ItemsSource, which is an IEnumerable. To add data dynamically, just Add elements to the data source

ObservableCollection<string> myData = new ObservableCollection<string>();

MyListView.ItemsSource = myData;

...

myData.Add("new item");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading