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

Change Cell Content Template

3 Answers 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
WILLIAM
Top achievements
Rank 1
WILLIAM asked on 10 Sep 2012, 08:37 PM
I have a scenario where I need to change the content template of a cell on a row by row basis.  Originally, the grid had two combo boxes.  Country and State, and the states would be populated based on the country chosen by the user.  As you can imaging if I have a two rows, one where country is Canada and one where the country is the US, the state column is going to be blank based on the last country that was selected.

Here is how I decided to tackle this issue:
I got rid of the combobox column and I'm just display plain text for the state in each row.  What I would like on the current focused row is switch out the text box and replace it with a combo box that is populated with states based on the country of the current focused row. When that row loses focus, go back to the text box.

In the xaml, I created a data template that has the combo box.  In my ViewModel I also created a TemplateSelector and Rules.

When the grid is loaded, I looped through the columns to find the state column and set it's CellTemplateSelector to the template selector in my view model.  This all worked fine, except that the selector is called one time for every row when the ItemsSource is set.

I need to make it fire when the focused row changes.

I did see the example of the conditional data template, but it seems the only way to do that is define all of the columns in the xaml.  I don't want to do this.  We already have a binding mechanism that creates the columns.

Also, we are not putting the row into "Edit" mode.  Currently it is displayed with empty text boxes and two combo boxes.

???

Thanks for your help!!

3 Answers, 1 is accepted

Sort by
0
WILLIAM
Top achievements
Rank 1
answered on 11 Sep 2012, 01:10 PM
???  I really need an answer on how to address this issue.
0
WILLIAM
Top achievements
Rank 1
answered on 12 Sep 2012, 01:19 AM
I guess this means that what I'm trying to do isn't easily accomplished.  So I'm trying to figure out ways to try to make this work.  So here's another thought.  GridViewComboBoxColumn has some properties, but no events.  How do I get the actual RadComboBox control that's associated with the column.  At that point I should be able to subscribe to the DropDownOpened and DropDownClosed events to filter the data manually right before it's displayed.

Also, The ComboBox has a FilterDataMemberPath.  I even tried setting this property to the path on the underlying data source, but that didn't work either.  This would be easier than subscribing to events.

Can someone please give some ideas on how to accomplish this?
0
Nick
Telerik team
answered on 14 Sep 2012, 06:16 AM
Hello William,

Have tried keeping the ComboBox ItemsSource in the Business model? That way you wont have to filter anything. Rather than that just bind the ItemsSource property of the ComboBoxolumn to the correct property in the Model.

Let me know what you think about it! 

Greetings,
Nik
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Tags
General Discussions
Asked by
WILLIAM
Top achievements
Rank 1
Answers by
WILLIAM
Top achievements
Rank 1
Nick
Telerik team
Share this question
or