views:

657

answers:

1

I have a radgridview which is bound to an object that I created, foo.

Object foo has a property 'status' that is populated from an enum.

I have many foo objects stored in a collection, which I use to bind to my radgridview.

Upon binding I get records and the grid displays fine.

I'd like to not display the 'status' enum value from my foo object within the grid. Instead, I'd like to use separate images that will depict the status more clearly (and in less space). Example, if foo's 'status' enum value == Open, I will display an open door and value == Closed would be a closed door. So the same column could have different images, but from the same property bound by foo's status enum. Hopefully that's clear enough...

I have tried overriding the content value with a bitmapimage within the RowLoaded event of the grid. I have also tried setting the data type of the grid to image, butmapimage, and image source to no avail...

Seems like this should be much easier than it is... If the image came straight from the database, it wouldn't be a problem; there's plenty of examples out there. However, doing it dynamically AND through code remain a mystery.

Thanks in advance for any assitance!

A: 

Apparently all I needed was to post the question...

I fell victim to trying way too many things at once and a soultion that should have worked perfectly didn't because I was trying a style on a cell at the same time.

In the example provided above, within the grid's RowLoaded event, one could do the following:

  1. Get the enum value from the cell content
  2. Create an Image control ( System.Windows.Controls.Image img = new Image(); )
  3. Assign the image's source depending upon the enum value ( open.png / closed.png )
  4. Set the cell's content = to the image control you just created

When the grid displays, you should see your image in the grid cell...

You also need to ensure the column's datatype is set to: typeof( System.Windows.Controls.Image )