1

I'm trying to populate a ListView with properties from a class that I have stored in a BindinglList, but it is only showing the object name. I'm unfamiliar with how to get the correct properties to bind to the correct headers. below is the code and screenshot of the wall im facing.

Issue I'm facing

This is my code:

public abstract class Part
{
   public int PartID { get; set; }
   public string Name { get; set; }
   public double Price { get; set; }
   public int Inventory { get; set; }
   public int Min { get; set; }
   public int Max { get; set; }
}
public class Outsourced : Part
{
   private string CompanyName { get; set; }

   public Outsourced(string name, int inventory, double price, int max, int min, string companyName)
   {

      Name = name;
      Inventory = inventory;
      Price = price;
      Max = max;
      Min = min;
      CompanyName = companyName;

   }

   public string GetCompanyName()
   {
      return CompanyName;
   }


}
public MainWindow()
{
   InitializeComponent();

   Outsourced part = new Outsourced("tire", 1, 3.00, 1, 1, "ddddd");
   Inventory.addPart(part);
   partsListview.ItemsSource = Inventory.PartsInventoryList;
}

This is my XAML:

<ListView  Margin="5" Name="partsListview" Height="250" >
   <ListView.View>
      <GridView >
         <GridViewColumn Header="Part ID" Width="90"></GridViewColumn>
         <GridViewColumn Header="Name" Width="90" ></GridViewColumn>
         <GridViewColumn Header="Inventory" Width="90"></GridViewColumn>
         <GridViewColumn Header="Price" Width="90"></GridViewColumn>
         <GridViewColumn Header="Min" Width="90"></GridViewColumn>
         <GridViewColumn Header="Max" Width="70"></GridViewColumn>
      </GridView>
   </ListView.View>
</ListView>
0

1 Answer 1

1

You have to use the DisplayMemberBinding property and bind it to the corresponding property of the data type Outsourced.

<ListView  Margin="5" Name="partsListview" Height="250" >
   <ListView.View>
      <GridView >
         <GridViewColumn DisplayMemberBinding="{Binding PartID}" Header="Part ID" Width="90"></GridViewColumn>
         <GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name" Width="90" ></GridViewColumn>
         <GridViewColumn DisplayMemberBinding="{Binding Price}" Header="Inventory" Width="90"></GridViewColumn>
         <GridViewColumn DisplayMemberBinding="{Binding Inventory}" Header="Price" Width="90"></GridViewColumn>
         <GridViewColumn DisplayMemberBinding="{Binding Min}" Header="Min" Width="90"></GridViewColumn>
         <GridViewColumn DisplayMemberBinding="{Binding Max}" Header="Max" Width="70"></GridViewColumn>
      </GridView>
   </ListView.View>
</ListView>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.