Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How to set the image inside a datagrid

How to set the image inside a datagrid

Scheduled Pinned Locked Moved WPF
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    salon
    wrote on last edited by
    #1

    I have a datagrid with itemsource as list. There should a column such that it will display image as well as text (Filename). The image will get displayed as per the filename extension, e.g. if the filename is test.doc then the word icon gets displayed and if the filename is test.pdf then the pdf icon gets displayed. Both the icon and the filname should remain in one column. And the datagrid should be filled at runtime with a webservice which gives the list.And the itemsource for the datagrid is that list. Can we acheive that? Thanks in advance,

    M 1 Reply Last reply
    0
    • S salon

      I have a datagrid with itemsource as list. There should a column such that it will display image as well as text (Filename). The image will get displayed as per the filename extension, e.g. if the filename is test.doc then the word icon gets displayed and if the filename is test.pdf then the pdf icon gets displayed. Both the icon and the filname should remain in one column. And the datagrid should be filled at runtime with a webservice which gives the list.And the itemsource for the datagrid is that list. Can we acheive that? Thanks in advance,

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      salon wrote:

      Both the icon and the filname should remain in one column.

      You can use a DataGridTemplateColumn[^] to specify the template for the column.

      salon wrote:

      The image will get displayed as per the filename extension

      One way you could do that is to use a IValueConverter[^] that takes the filename and returns a URI for the appropriate bitmap based on the filename extension. You would use this valueconverter in the Image.Source binding for the image in your column template. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups