Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7533725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:48:27+00:00 2026-05-30T05:48:27+00:00

I am trying to programatically add items to a ListView in WPF. I have

  • 0

I am trying to programatically add items to a ListView in WPF. I have done a lot of reading (including some questions here) and thought I was doing it correctly but the items aren’t showing up. As I understand it I create the ListViewe and bind it to a data source, in this case an ObservableCollection. I have verified the ObservableCollection is getting items added to it, but they aren’t getting displayed on the ListView. If it matters, the ListView is already instantiated by the time I run the LINQ query and attempt to add items to it.

Here is the XAML that defines the list view:

<TabPanel Name="ResultsTab" Height="200" Width ="500" DockPanel.Dock="Top" HorizontalAlignment="Left">
        <TabItem Name="Default_Tab" Header="Default">
            <ListView Name="DefaultListView" ItemsSource="Binding FCPortCollection">
                <ListView.View>
                    <GridView x:Name="DefaultGridView">
                        <GridViewColumn Width="Auto" Header="FC Port" DisplayMemberBinding="{Binding Path=FCPort}" />
                        <GridViewColumn Width="Auto" Header="WWPN" DisplayMemberBinding="{Binding Path=WWPN}"/>
                        <GridViewColumn Width="Auto" Header="FCID" DisplayMemberBinding="{Binding Path=FCID}" />
                        <GridViewColumn Width="Auto" Header="SwitchName" DisplayMemberBinding="{Binding Path=SwitchName}">
                        </GridViewColumn>                 
                    </GridView>   
                </ListView.View>     
            </ListView>
        </TabItem>

And here is the code that is supposed to load it.

public class PortResult
{
    public string SwitchName;
    public string FCPort;
    public string FCID;
    public string WWPN;

    public PortResult(string name, FCPort port)
    {
        SwitchName = name;
        FCPort = String.Format("fc{0}/{1}", port.SlotNum, port.PortNum);
        WWPN = port.WWPNList[0].WWPNValue;
        FCID = port.WWPNList[0].FCIDValue;

    }
}

ObservableCollection<PortResult> FCPortCollection = new ObservableCollection<PortResult>();

// results is an IEnumerable collection of FCPort result from a LINQ query that has been turned into a Dictionary
foreach (KeyValuePair<string, List<FCPort>> resultspair in results)
      {
            foreach (FCPort port in resultspair.Value)
            {    
                // create a new PortResult and add it to the ObservableCollection
                PortResult pr = new PortResult(resultspair.Key, port);
                FCPortCollection.Add(pr);
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:48:29+00:00Added an answer on May 30, 2026 at 5:48 am

    There are several problems in the code you posted:

    1. The binding syntax for your ItemsSource is missing the {} braces – it needs to be ItemsSource="{Binding FCPortCollection}"
    2. You can only bind to properties, however you only expose fields in your PortResult class. Change those fields to be properties.

    Also make sure the DataContext of the ListView is set to the object which contains the FCPortCollection. Also make sure the collection is a property of the object and not a field (same reason as point 2. above).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to programatically unzip a zipped file. I have tried using the
I am trying to programatically add a UITextFiled inside one of my tableview cells.
I am trying to programatically add a DIV with the class of error_icon to
I am trying to create a UIScrollView programatically. I have a scrollView for that
I've never used the ListView control before and am trying to programmatically insert items
I am trying to programmatically add a contact in Android. Here is my code:
Trying to fill the listbox programatically I have written the following code: protected override
I am trying to programatically add a startup item with LSSharedFileListInsertItemURL (the recommended method
Hi I'm trying to add a new tab and my controls programatically to visual
I've got a UITableView which has been created programatically. I'm now trying to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.