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

Reference Embedded Combo Box or TextBox within GridView

1 Answer 135 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alan Lee
Top achievements
Rank 1
Alan Lee asked on 26 Apr 2010, 08:35 PM
I can't find the API in gridview or gridviewdatacolumn to reference my embedded combo box or textbox. This is a multiple row and columns gridview and requires my user to select a combo box value that triggers textbox changes. Without a way to get the object reference during selection change event makes it very difficult.

For the example below, I need to reference object TxtTest3 on the same row where user select a value on CBTest2.

Any help is appreciated.


<Controls:RadGridView x:Name="DataTable" AutoGenerateColumns="False" ItemsSource="{Binding Path=Banks}"  Loaded="DataTable_Loaded" ShowColumnHeaders="True" IsFilteringAllowed="True" IsEnabled="True" CanUserSortColumns="True" ShowGroupPanel="False" CanUserSelect="False">
    <Controls:RadGridView.Columns>

        <Controls:GridViewDataColumn Header="Test" UniqueName="Test" >
            <Controls:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                <telerikControl:RadButton>
                <Image x:Name="ImageTest"  Source="{Binding Image}" Stretch="Fill" Tag="1" MouseDown="ImageTest_MouseDown" Loaded="ImageTest_Loaded"/>
                </telerikControl:RadButton>
            </DataTemplate>
            </Controls:GridViewDataColumn.CellTemplate>
        </Controls:GridViewDataColumn>

        <Controls:GridViewDataColumn DataMemberBinding="{Binding Test1}" Header="Test1"  UniqueName="Test1" IsReadOnly="True" />

        <Controls:GridViewDataColumn x:Name="CBTest2" Header="Test2" UniqueName="Test2">
            <Controls:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <telerikInput:RadComboBox Name="CBTest2" ItemsSource="{Binding Path=Test2Store, Mode=OneWay}"  SelectedValue="{Binding Path=Test2Value}" SelectedValuePath="Test2_id"  DisplayMemberPath="Test2info_value" Width="auto" Height="auto" Loaded="Test2_Loaded" SelectionChanged="Test2_Changed" />
                </DataTemplate>
            </Controls:GridViewDataColumn.CellTemplate>
        </Controls:GridViewDataColumn>

        <Controls:GridViewDataColumn x:Name="TxtTest3" Header="Test3" UniqueName="Test3">
        <Controls:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                <TextBox Name="TxtTest3" Style="{StaticResource TextBoxHighlighter}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" Loaded="Test3_Loaded" LostFocus="Test3_LostFocus" >
            </TextBox>
            </DataTemplate>
        </Controls:GridViewDataColumn.CellTemplate>
    </Controls:GridViewDataColumn>


</Controls:RadGridView>     

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 27 Apr 2010, 07:12 AM
Hi,

You can do this using our powerful extension methods ParentOfType<>() and ChildrenOfType<>(). Both methods are part of Telerik.Windows.Controls namespace. In your case for example you can get the parent grid row:

var row = ((RadComboBox)sender).ParentOfType<GridViewRow>();

and get desired child with ChildrenOfType<>():

var textBox = row.ChildrenOfType<TextBox>().Where(t=>t.Name == "TxtTest3").FirstOrDefault();

Kind regards,
Vlad
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
Alan Lee
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or