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

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

5 Answers 289 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raza
Top achievements
Rank 1
Raza asked on 10 Jun 2015, 08:58 AM

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;
        }

 

5 Answers, 1 is accepted

Sort by
0
Raza
Top achievements
Rank 1
answered on 10 Jun 2015, 09:00 AM

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>

0
Raza
Top achievements
Rank 1
answered on 11 Jun 2015, 10:20 AM
Any updates on my post..?
0
Dimitrina
Telerik team
answered on 11 Jun 2015, 10:49 AM
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
0
Muhammad
Top achievements
Rank 1
answered on 11 Jun 2015, 11:31 AM

Dimitrina 

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

0
Dimitrina
Telerik team
answered on 12 Jun 2015, 12:01 PM
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
Tags
GridView
Asked by
Raza
Top achievements
Rank 1
Answers by
Raza
Top achievements
Rank 1
Dimitrina
Telerik team
Muhammad
Top achievements
Rank 1
Share this question
or