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

bindig of list of objects into telerikGridView:GridViewDataColumn

8 Answers 382 Views
GridView
This is a migrated thread and some comments may be shown as answers.
lina fetisova
Top achievements
Rank 1
lina fetisova asked on 26 May 2010, 07:31 AM
Good day!
I have a class names Sales:

public class Sales : BaseDomain<br> 
{<br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual string Name { get; set; }<br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ICollection&lt;ActivityCategory&gt; categories = new  
List&lt;ActivityCategory&gt;();<br> 

I bind this a List of items of this class to a RadGridView:
grid.ItemSource = e.Result;
where e.Result is a List<Sales>.
For column "Name" I make it this way:
&lt;telerikGridView:GridViewDataColumn UniqueName="Name"&nbsp; Header="Name  
of Sale"&nbsp; /&gt;. 

How can I make it for ICollection<ActivityCategory> categories to show it in my RadGridView (maybe with a list of text  separated by commas  or with an dynamic number of chek boxes with text)?

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 26 May 2010, 07:36 AM
Hello,

You can check my answer in your other forum post.

All the best,
Vlad
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
lina fetisova
Top achievements
Rank 1
answered on 26 May 2010, 07:43 AM
Vlad, thank you very much, but can you provide me a more detailed answer, please?
0
Pavel Pavlov
Telerik team
answered on 26 May 2010, 07:46 AM
Hi lina fetisova,

To display a collection of values within a single cell , you will need to place an ItemsControl in the cell. Maybe a ListBox will do fine.
To place the ListBox you will need to use the CellTemplate property of the column.
It would be something like :
<telerik:GridViewDataColumn
    <telerik:GridViewDataColumn.CellTemplate
        <DataTemplate
        <ListBox ItemsSource ="{Binding categories}" />
        </DataTemplate
    </telerik:GridViewDataColumn.CellTemplate
</telerik:GridViewDataColumn


Alternatively you may represent the collection as a comma-separated list. For this you will need to use an IValueConverter in the DataMemberBinding of the  column. Within the Convert method of the IValueConverter you will need to turn the collection into a comma -separated string.

In case you have troubles implementing one of these approaches do not hesitate to contact me.


Regards,
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
lina fetisova
Top achievements
Rank 1
answered on 26 May 2010, 08:53 AM
thank you very much!

I write
<telerik:GridViewDataColumn
    <telerik:GridViewDataColumn.CellTemplate
        <DataTemplate
        <ListBox ItemsSource ="{Binding ActivityCategories}" />
        </DataTemplate
    </telerik:GridViewDataColumn.CellTemplate
</telerik:GridViewDataColumn

and see a result:

a list of strings: "CAP.Registrator.ActivityCategory"

CAP.Registrator.ActivityCategory has a property Name.
How can I see exactly this property?
0
Vlad
Telerik team
answered on 26 May 2010, 08:56 AM
Hello,

You can define desired ItemTemplate for this ListBox.

Greetings,
Vlad
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
lina fetisova
Top achievements
Rank 1
answered on 26 May 2010, 09:13 AM
oh! thank you very much, Vlad, Pavel !=)
everything is ok now!

<telerikGridView:GridViewDataColumn>
                    <telerikGridView:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <ListBox ItemsSource ="{Binding ActivityCategories}" >
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <TextBlock x:Name="txtAttributeName" Text="{Binding Name}"></TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </DataTemplate>
                    </telerikGridView:GridViewDataColumn.CellTemplate>
                </telerikGridView:GridViewDataColumn>

thank you very much!=) you are a wonderful team! =)
0
lina fetisova
Top achievements
Rank 1
answered on 26 May 2010, 09:23 AM
Oh, I have enother question:
how can I make sorting of grid with this column and enable filters for this column?

there are no filter and sorting by clicking the header of this column now

0
Pavel Pavlov
Telerik team
answered on 26 May 2010, 09:26 AM
Hi lina fetisova,

I believe you may find  this discussion helpful.

All the best,
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
lina fetisova
Top achievements
Rank 1
Answers by
Vlad
Telerik team
lina fetisova
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or