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

Customize RadGridView row or item

5 Answers 51 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hadrien
Top achievements
Rank 1
Hadrien asked on 15 Nov 2012, 10:06 AM
Hi,

I have this RadGridView:
<telerik:RadGridView x:Name="RadGridView1" GroupRenderMode="Flat" IsSynchronizedWithCurrentItem="True"
    IsReadOnly="True"
    AutoGenerateColumns="False"
    CanUserFreezeColumns="False"
    CanUserResizeColumns="True">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="#Case" DataMemberBinding="{Binding caseId}" Width="Auto"></telerik:GridViewDataColumn>>
        <telerik:GridViewDataColumn Name="CategoriesGridViewDataColumn" Header="Categories" Width="Auto">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <Grid Margin="0" Name="categoriesGird">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="1*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*"/>
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Row="0" Grid.Column="0" Background="Red"></TextBlock>
                        <TextBlock Grid.Row="0" Grid.Column="1" Background="Blue"></TextBlock>
                    </Grid>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
    </telerik:RadContextMenu.ContextMenu>
</telerik:RadGridView>

This give me something like the image in attachments.
As you can see I have 2 TextBlock for each row (column categories). But I want to fill the GridView table with information that I have in a a class that i created (number of categories is dynamic, so I want the number of TextBlock for each row depends how many categories i have in a list):
public class EmailTest
{
       public EmailTest() { }
 
       public EmailTest(string caseId, List<TextBlock> categories)
       {
          this.caseId = caseId;
          this.categories= categories;
       }
 
       public string caseId{ getset; }
       public List<TextBlock>categories{ getset; }
  }


How can I solve this problem?

5 Answers, 1 is accepted

Sort by
0
Hadrien
Top achievements
Rank 1
answered on 16 Nov 2012, 11:31 AM
Support, any idea?
0
Pavel Pavlov
Telerik team
answered on 16 Nov 2012, 02:49 PM
Hi Hadrien ,

I am attaching a working sample which displays multiple items in a cell achieved via placing an items control in the cell template.

Kind regards,

Pavel Pavlov
the Telerik team

 

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Hadrien
Top achievements
Rank 1
answered on 22 Nov 2012, 11:59 AM
Hi,

In this example you have a ObservableCollection<Player> object and then you just represent each object with the method ToString().
Imagine now that I have a Player class with 2 atributes: string name, string color. I want that the cell to be filled with the names, and each player name should written with it respective color (as you can see on right side of below image).

Thanks


0
Pavel Pavlov
Telerik team
answered on 22 Nov 2012, 12:06 PM
Hello,

This should be a routine :

1. Provide an ItemTemplate for the ItemsControl representing the players (a DataTemplate)
2. Inside the template place a TextBlock
3. Bind the text  of the TextBlock :  Text={Binding Path=name}
4. Bind the foreground of the TextBlock Path = Color ( actually you may need to create a solid color brush and bind its color)

Let me know in case you find troubles implementing the above mentioned approach.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Hadrien
Top achievements
Rank 1
answered on 22 Nov 2012, 08:21 PM
Thanks!
Tags
GridView
Asked by
Hadrien
Top achievements
Rank 1
Answers by
Hadrien
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or