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

How to use CellContentTemplateSelector in RadDataGrid when AutoGenerateColumns is On?

4 Answers 176 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Mikhail
Top achievements
Rank 1
Mikhail asked on 19 Sep 2018, 04:15 PM

Good day. 

I would like to use the CellContentTemplateSelector and AutoGenerateColumns in RadDataGrid control.

In your description(https://docs.telerik.com/devtools/universal-windows-platform/controls/raddatagrid/columns/how-to/datagrid-howto-usecellcontenttemplateselectorproperty) there is such use, but it is not for cases when AutoGenerateColumns is on.

How can I set an event handler similar to "AutoGeneratingColumn" (in WPF) which I can not find in the RadDadaGrid for UWP? 

Or is there some other solution?

P.S.I would have been satisfied with the program method for processing the event of automatic column generation, but I can not find this event. (like AutoGeneratingColumn in WPF )

4 Answers, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 21 Sep 2018, 09:40 AM
Hi Mikhail,

RadDataGrid for UWP provides a command for column generation. The GenerateColumn command can be used for customizing the logic for automatic generation of grid columns. For more details how to implement this please take a look at the following link: DataGrid: GenerateColumn Command.

I hope the provided information could help. 

Regards,
Didi
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

0
Mikhail
Top achievements
Rank 1
answered on 21 Sep 2018, 02:16 PM

 

Thanks for the answer.

Now I have another problem. My columns are not generated.

<controls:RadDataGrid x:Name="TableViewRelatedObjects"
                    HorizontalAlignment="Stretch"
                    DataContext="{x:Bind ViewModel}"
                    ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}"
                    AutoGenerateColumns="True"
                    UserGroupMode="Disabled">
</controls:RadDataGrid>

 

public class MyViewModel : ModelBase
{
    public ObservableCollection<IRelatedListObject> Items { get; set; }
}
 
public interface IRelatedListObject
{
    string ObjectId { get; set; }
    string LocalId { get; set; }
    string ObjectType { get; set; }
    bool CanDelete { get; set; }
}

 

As a result, only 4 columns are generated on the properteis which are described in the interface, but not the rest.

ItemSource and the result of the generation on the attached pictures.

0
Accepted
Didi
Telerik team
answered on 25 Sep 2018, 03:02 PM
Hi Mikhail,

Thank you for the provided code.

In order to show columns when the RadDataGrid GenerateColumCommand is used you should implement a custom logic inside the Execute method. The custom logic should specify for which property form the business object, the command could generate a column and its type.

I have prepared a sample project how this could be achieved. Please take a look at it and let me know if you have any other questions.

Regards,
Didi
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
0
Mikhail
Top achievements
Rank 1
answered on 25 Sep 2018, 04:40 PM

Thanks for the answer, I realized my mistake. I had to use dynamic properties. So I changed the ViewModel:

public class MyViewModel : ModelBase
{
    public ObservableCollection<System.Dynamic.ExpandoObject> Items { get; set; }
}

 

Generating columns works fine now!

 

Tags
DataGrid
Asked by
Mikhail
Top achievements
Rank 1
Answers by
Didi
Telerik team
Mikhail
Top achievements
Rank 1
Share this question
or