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

Binding complex object to gridView

1 Answer 173 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 04 May 2018, 10:38 AM

Hi, i've an complex object that i want to bind on my telerik gridview.

 

Object to binding in grid is a List<ReceiptRow>..where ReciptRow is this :

 

    public class ReceiptRow
    {
        protected Int32 rIndex;
        private string sku;
        private string description;
        private long quantity;
        private Totals rowAmmounts;
 
 
 
        public string Sku { get => sku; set => sku = value; }
        public string Description { get => description; set => description = value; }
        public long Quantity { get => quantity; set => quantity = value; }
        public Totals Ammounts { get => rowAmmounts; set => rowAmmounts = value; }
        public Int32 RIndex { get => rIndex; }
}

 

And where rowsAmmounts is a List<Totals> and totals object is : 

 

    public class Totals
    {
        private decimal vatAmount;
        private double vatRate;
        private decimal netAmount;
        private decimal grossAmount;
        public decimal VatAmount { get => vatAmount; set => vatAmount = value; }
        public double VatRate { get => vatRate; set => vatRate = value; }
        public decimal NetAmount { get => netAmount; set => netAmount = value; }
        public decimal GrossAmount { get => grossAmount; set => grossAmount = value; }
}

Which is the syntax for binding VatAmount, VatRate, NetAmount and GrossAmount in my gridview? I'll try with setting PropertyName to : "Totals.Ammounts.VatRate" or "Ammounts.VatRate" or simple VatRate, but i can't see the value on gridView,while i can see Description and Quantity without problem.

 

Here the xaml of gridView : 

<telerikDataGrid:RadDataGrid x:Name="gridTest" Margin="60,0,85,0" Grid.Row="18" Grid.Column="0" Grid.ColumnSpan="4" Grid.RowSpan="6" GridLinesVisibility="Both" UserFilterMode="Disabled" UserGroupMode="Disabled" UserSortMode="None" AutoGenerateColumns="False" >
    <telerikDataGrid:RadDataGrid.SelectionStyle>
        <telerikDataGrid:DataGridBorderStyle BackgroundColor="LightGray" BorderColor="Black" BorderThickness="1" />
    </telerikDataGrid:RadDataGrid.SelectionStyle>
    <telerikDataGrid:RadDataGrid.Columns>
        <telerikDataGrid:DataGridTextColumn PropertyName="Description" HeaderText="DESCRIPTION" Width="280" SizeMode="Fixed" >
            <telerikDataGrid:DataGridTextColumn.HeaderStyle>
                <telerikDataGrid:DataGridColumnHeaderStyle OptionsButtonTextColor="Transparent" BackgroundColor="Black" TextColor="White"
                                                           HorizontalTextAlignment="Center" TextFontSize="10"
                                           BorderColor="#D9D9D9"
                                           BorderThickness="1"/>
            </telerikDataGrid:DataGridTextColumn.HeaderStyle>
            <telerikDataGrid:DataGridTextColumn.CellContentStyle>
                <telerikDataGrid:DataGridTextCellStyle TextColor="White" HorizontalTextAlignment="Center"
                                               FontSize="12"
                                               SelectedTextColor="White"   />
            </telerikDataGrid:DataGridTextColumn.CellContentStyle>
        </telerikDataGrid:DataGridTextColumn>
        <telerikDataGrid:DataGridNumericalColumn PropertyName="Quantity"
                                         HeaderText="QTY" Width="100" SizeMode="Fixed">
            <telerikDataGrid:DataGridTextColumn.HeaderStyle>
                <telerikDataGrid:DataGridColumnHeaderStyle OptionsButtonTextColor="Transparent" BackgroundColor="Black" TextColor="White"
                                                           HorizontalTextAlignment="Center" TextFontSize="10"
                                           BorderColor="#D9D9D9"
                                           BorderThickness="1"/>
            </telerikDataGrid:DataGridTextColumn.HeaderStyle>
            <telerikDataGrid:DataGridDateColumn.CellContentStyle>
                <telerikDataGrid:DataGridTextCellStyle TextColor="White" FontSize="12" HorizontalTextAlignment="End" SelectedTextColor="White">
 
                </telerikDataGrid:DataGridTextCellStyle>
            </telerikDataGrid:DataGridDateColumn.CellContentStyle>
        </telerikDataGrid:DataGridNumericalColumn>
        <telerikDataGrid:DataGridNumericalColumn PropertyName="Totals.Ammounts.VatRate" CellContentFormat="{}{0:N}"
                                         HeaderText="VAT" Width="100" SizeMode="Fixed">
            <telerikDataGrid:DataGridTextColumn.HeaderStyle>
                <telerikDataGrid:DataGridColumnHeaderStyle OptionsButtonTextColor="Transparent" BackgroundColor="Black" TextColor="White"
                                                           HorizontalTextAlignment="Center" TextFontSize="10"
                                           BorderColor="#D9D9D9"
                                           BorderThickness="1"/>
            </telerikDataGrid:DataGridTextColumn.HeaderStyle>
            <telerikDataGrid:DataGridDateColumn.CellContentStyle>
                <telerikDataGrid:DataGridTextCellStyle TextColor="White" FontSize="12" SelectedTextColor="White" HorizontalTextAlignment="End">
 
                </telerikDataGrid:DataGridTextCellStyle>
            </telerikDataGrid:DataGridDateColumn.CellContentStyle>
        </telerikDataGrid:DataGridNumericalColumn>
        <telerikDataGrid:DataGridNumericalColumn PropertyName="Ammounts.GrossAmount" CellContentFormat="{}{0:N}"
                                         HeaderText="GROSS AMOUNT" Width="160">
            <telerikDataGrid:DataGridTextColumn.HeaderStyle>
                <telerikDataGrid:DataGridColumnHeaderStyle OptionsButtonTextColor="Transparent" BackgroundColor="Black" TextColor="White"
                                                           HorizontalTextAlignment="Center" TextFontSize="10"
                                           BorderColor="#D9D9D9"
                                           BorderThickness="1"/>
            </telerikDataGrid:DataGridTextColumn.HeaderStyle>
            <telerikDataGrid:DataGridDateColumn.CellContentStyle>
                <telerikDataGrid:DataGridTextCellStyle TextColor="White" FontSize="12" SelectedTextColor="White" HorizontalTextAlignment="End">
 
                </telerikDataGrid:DataGridTextCellStyle>
            </telerikDataGrid:DataGridDateColumn.CellContentStyle>
        </telerikDataGrid:DataGridNumericalColumn>
    </telerikDataGrid:RadDataGrid.Columns>
</telerikDataGrid:RadDataGrid>

 

Thanks in advance

 

 

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 09 May 2018, 10:52 AM
Hello,

I am afraid that currently nested properties are not supported in RadDataGrid.  I've logged this as a feature request in our public portal, you could cast your vote and subscribe for status changes at the following link: DataGrid: Support for nested properties

As a workaround you could use DataGridTemplateColumn instead, however, have in mind that it has some limitations compared to the other column types, for example, the filtering option is not available.

Let me know if I can assist with anything else.

Regards,
Yana
Progress Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
DataGrid
Asked by
n/a
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or