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

Seaching for controls in a cell template

2 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 15 Dec 2009, 04:56 PM

Hello everybody.
I have a RadGridView  whith three column teo of whic are displayed and edited using cell templates with a radComboBox and a TextBox

The following is the XAML code

<telerik:RadGridView x:Name="radGridDiscounts"  HorizontalAlignment="Left" Height="150" Width ="500" AutoGenerateColumns="False" ShowGroupPanel="False" MultipleSelect="False" ColumnsWidthMode="Fill" ItemsSource=""> 
    <telerik:RadGridView.Columns
        
<telerik:GridViewDataColumn Header="Descrizione" HeaderTextAlignment="Center" Width="200"
             DataMemberBinding="{Binding Description}" IsReadOnly="True" IsFilterable="False" />
       
<telerik:GridViewDataColumn Header="Tipologia sconto" HeaderTextAlignment="Center" Width="120" IsFilterable="False">
            <
telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <telerik:RadComboBox x:Name="radComboOperations"                                                                  
                                                              SelectionChanged
="radComboOperations_SelectionChanged   Loaded="radComboOperations_Loaded"
                                                              DisplayMemberPath
="Description" SelectedValuePath="Id"/>
                
</DataTemplate>
           
</telerik:GridViewColumn.CellTemplate>
      </telerik:GridViewDataColumn>
      <telerik:GridViewDataColumn Header="Valore" HeaderTextAlignment="Center" Width="75" IsFilterable="False" IsSortable="False"
        
<telerik:GridViewColumn.CellTemplate>
            <DataTemplate>
                <TextBox x:Name="textBoxValue" TextChanged="textBoxValue_TextChanged" Loaded="textBoxValue_Loaded"/>
           
</DataTemplate>
      
</telerik:GridViewColumn.CellTemplate>
    
</telerik:GridViewDataColumn>
  
</telerik:RadGridView.Columns>
</telerik:RadGridView>

So for every record displayed in the radGridView, "radComboOperations" is a radcombobox displayed in one cell template and "textBoxValue" is a textBox of the other cell template.

During the "_Loaded" operations of both controls I initialize properly the values must be displayed.
And there is no problem at all until now.

What do I have to do is to change Text or IsEnabled properties of "textBoxValue" of the corresponding Item ot the radGirdView, when a radComboOperations_SelectionChanged event of "radComboOperations" is raised.

The following is my function for the event

private void radComboOperations_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
   
RadComboBox comboBox = (RadComboBox)sender;
   
if (comboBox!=null)
   
{
        MyDTO dto = (MyDTO)comboBox.DataContext;
       
MyOperation Operation = (MyOperation)comboBox.SelectedItem;
       
if (Operation.Id == Guid.Empty)
        {
             //need help here where
            //I have to disable the textBoxValue of the corresponding item of the radGridView
            //where and how can I find the textBoxValue text box of the cell template??
        }
    }
}

I will thank a lot everyone may help me!!
Bye everybody
Nick

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 16 Dec 2009, 07:50 AM
Hi Nick,

 You can use our powerful extension methods to achieve your goal. Here is an example how to get parent row:

var row = comboBox.ParentOfType<GridViewRow>();

And here is an example how to get textBoxValue TextBox from the row:

var textBoxValue = row.ChildrenOfType<TextBox>().Where(tb=>tb.Name == "textBoxValue").FirstOrDefault();

Both extension methods are part of Telerik.Windows.Controls namespace (you need to register this if you to work with these methods).


Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nick
Top achievements
Rank 1
answered on 16 Dec 2009, 09:25 AM
Thank you very much Vlad.
It was a helpful suggestion!!

Bye

Nick
Tags
GridView
Asked by
Nick
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Nick
Top achievements
Rank 1
Share this question
or