Skip to main content

Microsoft Silverlight

Answered Question How to add an image column to a bound datagrid when the image has to be generated based on a datavalue of a column?RSS Feed

(0)

ymo519
ymo519

Member

Member

20 points

10 Posts

How to add an image column to a bound datagrid when the image has to be generated based on a datavalue of a column?

I have a datagrid which uses a wcf serrvice to get populated.

datagrid.itemssource = e.Result;

Now i have to modify the data of column of int datatype into images based on the values.

For Example: If r = 1, show correct icon else show wrong Icon.

This should be done at run-time.

If there is some sample code, it would be helpful..

Thank You 

 

 

JKewley
JKewley

Member

Member

14 points

3 Posts

Re: How to add an image column to a bound datagrid when the image has to be generated based on a datavalue of a column?

Try this:
http://silverlight.net/forums/t/14714.aspx

based upon this:
http://silverlight.net/forums/p/11614/38274.aspx

 

ymo519
ymo519

Member

Member

20 points

10 Posts

Re: How to add an image column to a bound datagrid when the image has to be generated based on a datavalue of a column?

Can i know how did u set the datacontext?

Is the Datacontext for the particular column mentioned ur post generated from a WCF service?

My datagrid is populated from a WCF service.

I am not able to set the datacontext for particular column.

sladapter
sladapter

All-Star

All-Star

17427 points

3,171 Posts

Answered Question

Re: How to add an image column to a bound datagrid when the image has to be generated based on a datavalue of a column?

I assume the return value (e.Result) from your WCF call is a list object (or a object Array)?  When you set the DataGrid.ItemSource = e.Result, each UIElement in the DataGrid will automatically has a DataContext set which is the Data Object for that particular row. So you can access to it.

If you set a Image control for a column in the Data Template. You hook up a Loaded event handler for it.  On Loaded event handler , you get the Data for that Row, do some checking then set the Image.Source accordingly:

     private void Image_Loaded(object sender, RoutedEventArgs e)
        {
             Image i = sender as Image;
             MyDataObject d = i.DataContext as MyDataObject;

             if(MyDataObject.Field1 == "something")

            {
                 i.Source = ImageURL;

            }
          
       }


 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities