This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi There, I have a strange customer ask something like this: In a DataGrid for the same column, it can have different editing controls from different rows. In the attached file, column "value", for the first record, it uses textbox, and for the 2nd-5th use comboBox with different dropdowns for different items. Can we do that on the DataGrid? How? Thanks a lor, Gordon |
|
|
Hello Gordon Yes this can be done by implementing a DataTemplateSelector. Start by creating a new class the extends the DataTemplateSelector class. Override the SelectTemplate method. In this method, the "item" parameter will give you the data context of a row in the data grid. from this item, you can access its properties and use what ever logic you need to choose a template. The template you return could either be built in code on the spot, or acquired from some kind of template store, or from custom properties you implement on the DataTemplateSelector implementation. The template that gets returned can contain any control you want, even combo boxes with different items based on your selection logic. Once you have implemented a template selector, you can use the usual approach to add a DataGridColumn instance to the DataGrid.Columns collection. But instead of setting the EditorTemplate property, you can set the EditorTemplateSelector property to be an instance of your custom data template selector. Jason Fauchelle |
|