C# – Add programmatically ListViewItem to Listview in WPF


Possible Duplicate:
WPF ListView – how to add items programmatically?

How it can be done in C#?

Best Solution

This is how you would add a ListViewItem created in code to your ListView:

myListView.Items.Add(new ListViewItem { Content = "This is an item added programmatically." });

However, I agree with MrTelly that this shouldn't be necessary, you should be setting ListView.ItemsSource to some collection rather than manipulating ListView.Items directly.

If you give us more details about what you want to accomplish maybe we can help you do it the WPF way, which is not always the easy way at first, but it's much easier in the long run.