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

Dynamic Data Object Column Type Binding

2 Answers 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maurice
Top achievements
Rank 1
Maurice asked on 21 Feb 2018, 04:23 AM

When binding to a dynamic object in the grid, we all know that the Dynamic column will be treated as an object and the cell templates will not be what is expected for some columns. Is there a property on the Column (I haven't found one digging in the source yet) to set the columns data type or do I need to use a Template Selector to achieve this per column that I don't want to be treated as a string?

 

Thanks,
Maurice

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 23 Feb 2018, 09:49 AM
Hello Maurice,

If I understood your requirement correctly, you can set the DataType property of the GridViewDataColumn in the AutoGeneratingColumn event, like so:

private void Grid_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
    var column = e.Column as GridViewDataColumn;
    if (e.ItemPropertyInfo.Name == "IsDirty")
    {
        column.DataType = typeof(bool);
    }
    else if (e.ItemPropertyInfo.Name == "Date")
    {
        column.DataType = typeof(DateTime);
    }
}

For your convenience, I've attached a small sample project demonstrating this approach.

Please let me know if this is what you had in mind. If that is not the case, please provide more details on your exact requirement so that I can better assist you. I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Maurice
Top achievements
Rank 1
answered on 23 Feb 2018, 03:46 PM

Thank you, Dilyan, I am not sure how I missed seeing that.

Regards,
Maurice

Tags
GridView
Asked by
Maurice
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Maurice
Top achievements
Rank 1
Share this question
or