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

adding columns manually in c#

1 Answer 184 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Isaac
Top achievements
Rank 1
Isaac asked on 26 Mar 2013, 09:09 PM
Hi,

I am trying your product and I need some help.

I have a List<DataClass> to set as the itemsource for the RadDataGrid.ItemSource.

But I want to generate the column manually because I only want certain member of the object DataClass to be displayed.

Say the DataClass has 5 Members.

FirstName
LastName
Age
Address
Telefon

it depends on some external event such that, say, in this particular case, I only want to show FirstName, LastName and Address.

Can you show me how to use c# to set the Columns properties, Header, or anything else I need to map this list<DataClass> to the DataGrid?

Thanks

1 Answer, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 29 Mar 2013, 04:57 PM
Hi Isaac,

Thank you for contacting us.

Yes, the described scenario is possible. First, you need to set RadDataGrid.AutoGenerateColumns to false. Then, after this list is set as a DataContext of the RadDataGrid, you can manually add columns depending on your logic like this: 
DataGridTextColumn column = new DataGridTextColumn();
column.PropertyName = "FirstName";
column.Header = "FIRST NAME";
this.grid.Columns.Add(column);

I hope this helps. Let me know if you need further assistance.

 

All the best,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Grid for XAML
Asked by
Isaac
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Share this question
or