Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

Bindable CellContentFormat into DataGridTextColumn

$
0
0
Hi Johan,

Let me start with a question, so that I am sure I am getting this right -- you might have different kind of values within the same column, so that you might need one format on item 1 (row 1) and another on item 2, is that correct? In this case, the short answer is -- this cannot be done through CellContentFormat property of the column.

You can use DataGridTemplateColumn instead. You can place just a single TextBlock within the CellContentTemplate and bind it to the DataContext. Then you can add a converter, which in this case, will receive the entire business object, so that you can retrieve the value, the format and return the text to be shown as per your requirements.

<telerikGrid:DataGridTemplateColumn>
    <telerikGrid:DataGridTemplateColumn.CellContentTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Converter={StaticResource converter}}"></TextBlock>
        </DataTemplate>
    </telerikGrid:DataGridTemplateColumn.CellContentTemplate>
</telerikGrid:DataGrid

And the converter might be similar to this:

public object Convert(object value, System.Type targetType, object parameter, string language)
        {
            MyDataItem data = value as MyDataItem;
            return data.Value.ToString(data.Format);
        }


Best regards,
Ves
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

Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>