This is a migrated thread and some comments may be shown as answers.

Newbie - Trying to show Image in cells

3 Answers 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bruce Chapman
Top achievements
Rank 1
Bruce Chapman asked on 08 Jan 2010, 03:42 PM
Here is the class that populates each row:

 

    public class TableData  
    {  
        private string name;  
        private Image image = new Image();  
 
        public string Name  
        {  
            get { return name; }  
            set { name = value; }  
        }  
        public Image Picture  
        {  
            get { return image; }  
            set { image = value; }  
        }  
        public TableData(string s)  
        {  
            Name = s;  
            image.Source = new BitmapImage(new Uri("captain-scarlet.jpg", UriKind.RelativeOrAbsolute));  
        }  
    }  
 

Here is how I set up the grid:

 

            ObservableCollection<TableData> theData = new ObservableCollection<TableData>();  
            theData.Add(new TableData("1a"));  
            theData.Add(new TableData("2a"));  
            radGridView1.ItemsSource = theData;  
 

 


The grid view appears and the name column shows data ok, but the image column is blank.
I see in the debugger that both columns in the grid are of type GridViewDataColumn. Should the image one be a GridViewImageColumn? If so, how do I set it up?

Any help appreciated - I'm trying to evaluate it for a potentially big project!
Thanks
Bruce


 

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Jan 2010, 07:20 AM
Hi Bruce,

The grid will not generate automatically GridViewImageColumn for auto-generated columns - you can declare this column manually similar to this demo:
http://demos.telerik.com/wpf/?GridView/ColumnTypes

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bruce Chapman
Top achievements
Rank 1
answered on 11 Jan 2010, 11:10 PM
Thanks for that. Are there any samples that show how to set up a GridViewImageColumn in C# code rather than in XAML. I can't seem to figure it out.

Many thanks
Bruce
0
Vlad
Telerik team
answered on 12 Jan 2010, 07:19 AM
Hello Bruce,

All you need is to create the column, assign DataMemberBinding and add the column to the Columns collection:

var column = new GridViewImageColumn() { DataMemberBinding = new Binding("YourImageProperty") };
RadGridView1.Columns.Add(column);

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Bruce Chapman
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Bruce Chapman
Top achievements
Rank 1
Share this question
or