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

How Do I Populate the Values Of A Custom Cell Control?

1 Answer 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 28 May 2010, 12:26 PM
I have a grid that has two columns: Field and Value. Field never changes and is uneditable. Value can contain a number of different controls based on a configuration file all of which are custom implementations of standard controls such as the ComboBox, Textbox, Button, etc, and all of which are determined and created at runtime.

At some point my program is going to receive some data that needs to be programmatically populated into the Value column of each row, but the control that contains the value obviously has a different way of setting the "value."

My first question, however, is that given a reference to a grid in the code behind (in C#) how do I access the actual control object of the Cell of a given row? There appears to be no such collection as "this.myGrid.Cells" or "this.myGrid.Rows." I was thinking if I could access the value of each cell directly I could just have a large if statement to act accordingly based on the cell's content control type.

If that is not possible is there some way to bind, for example, the custom control's TextBox so that when I do something like:

this.myGrid.ItemSource = myDataTable;  
this.myGrid.Rebind(); 

the data in each cell of myDataTable is set in in the Text property of TextBox? Remember though, all this must be done programmatically.

Does this make sense? I really need help on this one. If you need further code examples of anything I have mentioned doing please let me know so I can provide them.

Thanks.



1 Answer, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 28 May 2010, 02:30 PM
Hi Andrew,

 I suggest that you use the CellTemplateSelector property in your Value column. This way you'll be able to create DataTemplates for the cell programmatically, by extending the DataTemplateSelector class. You can find more information about it here.

Your DataTemplateSelector implementation will be called before every cell is created. You'll be able to access the business object bound to the cell and the cell itself. This way, you can create (or load from an external XAML ResourceDictionary, which would be better) the template for each cell and pass it on to the RadGridView. Within the template, you can define any bindings you like.

If you need further assistance, please don't hesitate to contact us again.

Sincerely yours,
Yavor Georgiev
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Share this question
or