RadGridView Bound to datatable for dynamic unknown number of columns. CellTemplate and CellEditTemplate Not working.

6 posts, 0 answers
  1. Raza
    Raza avatar
    5 posts
    Member since:
    Feb 2014

    Posted 10 Jun 2015 Link to this post

    Hi

       I am trying to use Datatable in my radgridview for items source. It works fine with premitive datatypes for columns. But when you try to add a custom object as a column, and provide a celltemplate in autogenerate columns event in code behind then the datatemplate is not picking the object context. In output window its showing a binding error from datatemplate for the properties I have provided from my object in the cell. The error for each cell I am getting in my output window is: Error: 40 : BindingExpression path error: 'PropertyValue' property not found on 'object' ''DataRow' (HashCode=45554962)'. Any idea if I am missing any thing..

     Below is my code in code behind file. Assum my all columns are of same type and they need a cell template and an celledittemplate.

     

     private void ResourcesListGridView_OnAutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
            {
               
                var editModel = Application.Current.TryFindResource(CommonKeys.CostValueModelEditor);
                var cellmodel = Application.Current.FindResource(CommonKeys.CostValueModel);
                if(editModel!=null)
                 e.Column.CellEditTemplate = editModel as DataTemplate;
                if(cellmodel!=null)
                e.Column.CellTemplate = cellmodel  as DataTemplate;
            }

     

  2. Raza
    Raza avatar
    5 posts
    Member since:
    Feb 2014

    Posted 10 Jun 2015 in reply to Raza Link to this post

    And following is my Template.

     

    <DataTemplate x:Key="{x:Static common1:CommonKeys.CostValueModel}" DataType="common:CostValuesModel" >
            <TextBlock Text="{Binding Path=PropertyValue}" Foreground="{Binding Path= IsEqual, Converter={StaticResource BoolToColorConverterResource}}" />
        </DataTemplate>

  3. Raza
    Raza avatar
    5 posts
    Member since:
    Feb 2014

    Posted 11 Jun 2015 in reply to Raza Link to this post

    Any updates on my post..?
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 11 Jun 2015 Link to this post

    Hello,

    It seems the DataTemplate presents a TextBlock set to the binding to PropertyValue property.
    Is PropertyValue a property of the bound data item? Can you access it in code?

    Looking at the test of the error, it says the DataRow object does not expose a PropertyValue property. Would you please try binding RadGridView to DataTable.DefaultView instead?

    Let me know if this works for you.

    Regards,
    Dimitrina
    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
  5. Muhammad
    Muhammad avatar
    1 posts
    Member since:
    Apr 2015

    Posted 11 Jun 2015 in reply to Dimitrina Link to this post

    Dimitrina 

                    It didnt work. I sent you an image in my support ticket for further details.

  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 12 Jun 2015 Link to this post

    Hi,

    Thank you.
    Exploring the demo solution you sent in the support ticket, it turned out the bound data object does not directly expose those properties, they are actually nested to CustomValue.
    I would suggest you modifying the DataTemplates like so:
    <DataTemplate x:Key="CellModelTemplate" >
        <TextBlock Text="{Binding Path=CustomValue.PropertyValu1}" ToolTip="{Binding Path=CustomValue.PropertyValu2, StringFormat= Actual Value: {}{0}}"/>
    </DataTemplate>
    <DataTemplate  x:Key="CellModelEditTemplate" >
        <TextBox Text="{Binding Path=CustomValue.PropertyValu2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
    </DataTemplate>


    That way the values will be populated fine.

    Regards,
    Dimitrina
    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
Back to Top