Click here to Skip to main content
15,916,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want to bind the DataGrid in MVVM with dynamica create column. i don't know how to Implement please help. i have taken many reference form google search but not any works.

below are the my tried code please help.
i am using vs 2012.


thanks in advance.

What I have tried:

in xaml file code:
<datagrid x:name="DataGridUsers" xmlns:x="#unknown">
ItemsSource="{Binding Users}"
attachedBehaviors:DataGridColumnsBehavior.BindableColumns="{Binding UserRoleColumns}"
AutoGenerateColumns="False"
EnableRowVirtualization="False"/>

viewModel file code:

private void GenerateDefaultColumns()
{
this.UserRoleColumns.Add(
new DataGridTextColumn { Header = "First Name", Binding = new Binding("FirstName") });
this.UserRoleColumns.Add(new DataGridTextColumn { Header = "Last Name", Binding = new Binding("LastName") });
}
public ObservableCollection<datagridcolumn> UserRoleColumns { get; private set; }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900