How to set the image inside a datagrid
-
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,
-
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,
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: