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 144051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:11:32+00:00 2026-05-11T08:11:32+00:00

Couldn’t find an answer to this one. I have a WPF ListView control that

  • 0

Couldn’t find an answer to this one.

I have a WPF ListView control that can contain varying number of columns. For example, it can display customer data, displaying columns Id, Name, Email etc, or it can contain products, displaying ID, Name, Price, NumberInStock, Manufacturer, well, you get the idea: varying number of columns, varying names.

What I want to do, is for certain columns to display the data differently. For example, instead of printing ‘Yes’ or ‘No’ as the value of the column NumberInStock, I want to display a neat image.

If I’d have a fixed amount of columns, with fixed names to bind to, I kinda see how this is easy. Just define a DataTemplate for that particular column and I’d use that to define the view of my column. However, I can’t see how to do it in my situation.

I am very new to WPF, so excuse me if my approach is bad 🙂 In my XAML, I have defined a ListView control, which is pretty much empty. In my code behind, I use:

    // get all columns from my objects (which can be either a Customer of Product)     foreach (string columnName in MyObject.Columns)         {           GridViewColumn column = new GridViewColumn();           // Bind to a property of my object           column.DisplayMemberBinding = new Binding('MyObject.' + columnName);           column.Header = columnName;           column.Width = 50;           // If the columnname is number of stock, set the template to a specific datatemplate defined in XAML           if (columnName == 'NumberInStock')             column.CellTemplate = (DataTemplate)FindResource('numberInStockImageTemplate');           explorerGrid.Columns.Add(column);         } 

Ok, I’m sure this could be done a bit prettier (if you have any advice, please!) but the biggest problem is that I can’t see any difference in the column. It just displays the text value of the ‘NumberInStock’ column. My DataTemplate is defined in the XAML:

<Window.Resources> <DataTemplate x:Name='NumberInStock' x:Key='NumberInStock'>       <Border BorderBrush='Red' BorderThickness='2.0'>         <DockPanel>           <Image Width='24' Height='24' Margin='3,0' Source='..\Images\instock.png' />         </DockPanel>       </Border> </DataTemplate> </Window.Resources> 

Of course, I would still have to add the functionality that it would display a ‘yes’ or ‘no’ image depending on the value of NumberInStock, but that is step 2 really. I would be happy to see an image and a red border in my ListView!

Thanks in advance, Razzie

  • 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. 2026-05-11T08:11:32+00:00Added an answer on May 11, 2026 at 8:11 am

    This tripped me up for a while.

    DisplayMemberBinding and CellTemplate are mutually exclusive. Specifying a DisplayMemberBinding causes the CellTemplate to be ignored.

    From MSDN:

    The following properties are all used to define the content and style of a column cell, and are listed here in their order of precedence, from highest to lowest:

    * DisplayMemberBinding * CellTemplate * CellTemplateSelector 

    Also see a C# Disciples post about this.

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

Sidebar

Ask A Question

Stats

  • Questions 164k
  • Answers 164k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In Cocoa, you rarely (if ever) call drawRect - you… May 12, 2026 at 12:28 pm
  • Editorial Team
    Editorial Team added an answer PHP's SimpleXml is an object that implements the ArrayAccess interface… May 12, 2026 at 12:28 pm
  • Editorial Team
    Editorial Team added an answer The way to figure this out: on the page you… May 12, 2026 at 12:28 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Couldn't a DSL be as simple as an API and therefore not need a
Couldn't find an answer to this one. I have a WPF ListView control that
Couldn't creatively shorten the title :) I have been using a variation of the
Couldn't find any good information on how to do this so I thought I'd

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.