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

RadGridView: How to set Item Source at cell level for template columns?

5 Answers 75 Views
GridView
This is a migrated thread and some comments may be shown as answers.
sukhdev singh
Top achievements
Rank 1
sukhdev singh asked on 22 Mar 2010, 05:14 AM

Hi,
 

I have atleast following four things for CellTemplate
#1: Item Title
#2: Item Image
#3: Item Description
#4: DURATION

Values for these four items is different for different cells, which are determined at run time. Moreover, the height of every cell is determined by the DURATION at run time, Which means the height of cells may not be same across rows.

Could you please guide me how to use RadGridView for my requirement?
Thanks in advance!!

Regards,
Sandy

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 22 Mar 2010, 10:25 AM
Hi sukhdev,

Please paste me the implementation of your business object ( the one with the properties : Title, Image, Description and Duration) I will gladly prepare a small sample for you .

As a general guidance : The DataContext of the cell is the whole business object, so in the CellTemplate Property of the column you should place a data template with the controls neccessary .
For example your data template may look something  like :

<telerik:GridViewDataColuumn.CellTemplate>
<DataTemplate>
    <TextBlock Text={Binding Title} />
    <TextBlock Text={Binding Description} />
    <TextBlock Text={Binding Duration} />
</DataTemplate>
</telerik:GridViewDataColuumn.CellTemplate>


Sincerely yours,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
sukhdev singh
Top achievements
Rank 1
answered on 23 Mar 2010, 05:30 PM
Hi Pavel,

Psuedo code is as follows

public class cItemDetails 
{

    public string itemTitle { get; set; } 
    public string displayImageSrc{ get; set; }

    public string itemDescription{ get; set; }

    public int itemDuration{ get; set; }
}

List<cItemDetails> lstItemDetailsColumnWise; //for simplicity, code for filling lstItemDetailsColumnWise with objects of cItemDetails  is removed

//XAML Code
<DataTemplate x:Key="myCellTemplate">
    <TextBlock Text="{Binding itemTitle}" />
    <Image Source="{Binding displayImageSrc}"/>
    <TextBlock Text="{Binding itemDescription}"/>
    <TextBlock Text="{Binding itemDuration}"/>
</DataTemplate>

I am stuck because of following limitations
#1: lstItemDetailsColumnWise is the list of data source objects for cells in a column but I am not able to find the way how to set ItemSource at column level in RadGridView?
GridViewColumn grdViewColumn = new GridViewColumn();
grdViewColumn.CellTemplate = (DataTemplate)Resources["myCellTemplate"];
GridViewLength dataGridLen = new GridViewLength(300.0);
grdViewColumn.Width = dataGridLen;
grdViewColumn.ItemSource = ????? (Not there?)

#2: To avoid limitation#1, if I create GridViewCell and set DataContext as follows
GridViewColumn grdViewColumn = new GridViewColumn();
GridViewCell grdViewCell = new GridViewCell();
grdViewCell.ContentTemplate = (DataTemplate)Resources["myCellTemplate"];  
grdViewCell.DataContext = lstItemDetailsColumnWise[i]; // i varies from 0 to n (lstItemDetailsColumnWise.Count - 1)
grdViewColumn.Add(grdViewCell) - ????? (Not there?)

Here I don't know how to set grdViewCell in RadGridViewDataColumn?

#3: If I create double list of cItems and set it as ItemSource of RadGridView as follows
List<List<cItems>> dblListItemDetails //Code of adding contents in this list is not shown here for simplicity sake
RadGridView.ItemSource = dblListItemDetails;
Result: RadGridView is not able to populate the data from double list

Here, you will find that I am stuck with all the options where in first two options worked fine when I was using Silverlight Grid control.
I prefer to use Option#2, control at cell level because cell height depends on ItemDuration, which means cell height will not be same across cells in any particular Row in RadGridView. I don't know if RadGridView can have row with cells of different heights, may be CellSpan will come to rescue.

Why is it so difficult to use RadGridView control when you have requirement of binding every cell with multiple properties whose values come from separate business object for each cell?
I want to have control at cell level for setting contents of the cell and also setting the height of every cell.
Is it possible with RadGridView?
Please help!!

Thanks,
Sukhdev

Pavel, Could you please reply to my post? I am wondering why there is no way to add GridViewCell to GridViewColumn or GridViewDataColumn by code? I can set height, content, contentemplate, datacontext for GridViewCell but then what is its use for me if I am not able to add it to column of my choice?

0
Pavel Pavlov
Telerik team
answered on 24 Mar 2010, 02:40 PM
Hi sukhdev singh,

RadGridView as all DataGrids is intended to work with the following data structure :
A list (typically some kind of IEnumerable) of business objects  which is given to RadGridView trough the ItemsSource property.
Each business object is visually represented as row where each cell represents a property of that business object.

Any data that should be represented in a tabular manner may be parsed / processed  and passed to the RadGridView in this form .

In my opinion the best solution to your problem is to process your data to a tabular view as the one described above  and the result to be given to the RadGridView.
In other words - the proper ViewModel implemented so that it can act as a middle layer of your data and the Gridview should do the job.

PS. Cell merging ( vertical or horizontal ) is not natively supported by RadGridView ...yet.


Best wishes,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
sukhdev singh
Top achievements
Rank 1
answered on 26 Mar 2010, 01:24 PM
Hi Pavel,

Are you saying that RadGridView doesn't allow to use same set of properties for every cell in any particular row? Is it like the property you assign to every column is going to be unique and cannot be used for other column in the Grid.
It sounds pretty strange to me.
I can assign the set of properties to celltemplate for every cell and then at rune time I get the values for these properties by business objects.
is it that RadGridView not suitable for kind of requirement I have? please confirm

Thanks,
Sukhdev
0
Pavel Pavlov
Telerik team
answered on 29 Mar 2010, 04:19 PM
Hi sukhdev singh,

What i am trying to say is that you need the proper view model so you can display your datai in RadGridView.

For example :
You may bind the radGridView to a list of Row objects , where the implementation of Row looks something like :

class Row
{
public Item  Item1
{
    get;
    set;
}
public Item Item2
{
    get;
    set;
}
public Item Item3
{
    get;
    set;
}

etc.

}

And the implementation of the Item object may look something like :

class Item
{
  public string itemTitle { get; set; } 
  public string displayImageSrc{ get; set; } 
  public string itemDescription{ get; set; }
  public int itemDuration{ get; set; }
}


Then you may bind RadGridView to a List<Row>
and use the following cell template for the rfirst column :

<DataTemplate x:Key="myCellTemplate">
    <TextBlock Text="{Binding Item1.itemTitle}" />
    <Image Source="{Binding Item1.displayImageSrc}"/>
    <TextBlock Text="{Binding Item1.itemDescription}"/>
    <TextBlock Text="{Binding Item1.itemDuration}"/>
</DataTemplate>

the following cell template for the second column :

<DataTemplate x:Key="myCellTemplate">
    <TextBlock Text="{Binding Item2.itemTitle}" />
    <Image Source="{Binding Item2.displayImageSrc}"/>
    <TextBlock Text="{Binding Item2.itemDescription}"/>
    <TextBlock Text="{Binding Item2.itemDuration}"/>
</DataTemplate>

and so on ....


Best wishes,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
sukhdev singh
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
sukhdev singh
Top achievements
Rank 1
Share this question
or