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

[Solved] Accessing cell template and edit template in code behind

1 Answer 256 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rajagopalan
Top achievements
Rank 1
Rajagopalan asked on 25 Aug 2011, 10:41 AM
Hi,
We have a requirement where in in radgridview data column's cell template we have set the collection's property and in edit template, we have a combobox.  Now, based on the radgridcombocolumn which is nothing other than the previous column selection, i have to show the values in the edit template combobox.  If I select some values in the edit template combo box, it wont set because I have applied a textblock and bind the value to some property. 
In order to change the property of the textblock, I have to access the same in code behind and set the selecteditem value of the combobox.
Kindly help.

<

 

 

telerik:GridViewDataColumn Header="State" UniqueName="StateComboColumn" IsGroupable="False" HeaderCellStyle="{StaticResource MyHeaderCellStyle}" TextAlignment="Right" >

 

 

 

 

<telerik:GridViewColumn.CellTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<TextBlock Text="{Binding stateName}"/>

 

 

 

 

 

</DataTemplate>

 

 

 

 

</telerik:GridViewColumn.CellTemplate>

 

 

 

 

<telerik:GridViewColumn.CellEditTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<telerik:RadComboBox ItemsSource="{Binding StateCollection}" DisplayMemberPath="name" DropDownOpened="RadComboBox_DropDownOpened"/>

 

 

 

 

</DataTemplate>

 

 

 

 

</telerik:GridViewColumn.CellEditTemplate>

 

 

 

 

</telerik:GridViewDataColumn>

 

 

 

private void RadComboBox_DropDownOpened(object sender, EventArgs e)

 

{

 

 

RadComboBox objTempRadCombo = sender as RadComboBox;

 

objTempRadCombo.ItemsSource = StateCollection;

objTempRadCombo.DisplayMemberPath =

 

"name";
//HOw do I set the textblock to the selecteditem of this combobox here?

 

}

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 25 Aug 2011, 05:08 PM
Hi Rajagopalan,

Your requirement seems to totally fit the GridViewComboBoxColumn purpose. I was wondering why do you avoid using it .

Now on the issue :

To have things working correctly you need to :
1. Bind the SelectedValue of the combo to the property you need to be edited
2. This property should raise the PropertyChangedEvent form the INotifyPropertyChanged interface.
3. Then the TextBox should be also bound.

If you have these 3 conditions, things should be OK.
As alternative - you can just use the Combo column , as it does pretty much the same.

All the best,
Pavel Pavlov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Rajagopalan
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or