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

Finding control inside gridview row.

5 Answers 253 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Amit Patel
Top achievements
Rank 1
Amit Patel asked on 20 Oct 2009, 07:32 PM
I have xaml code setup for grid view and have combo box in it. I would like to get the reference of combo box during runtime when user clicks on the row. I have the OnGridViewRowSelection event setup. I have already tried FindName methods on cell, row and grid to find the combo box, but on each case I am keep on getting null reference for comboBox.

Thanks,
Amit

5 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 21 Oct 2009, 07:14 AM
Hi,

You can use our extension methods to achieve your goal. Here is an example:

XAML
    <telerikGrid:RadGridView MouseLeftButtonUp="RadGridView_MouseLeftButtonUp">
            <telerikGrid:RadGridView.Columns>
                <telerikGrid:GridViewColumn>
                    <telerikGrid:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox Name="MyCombo">
                                <ComboBox.Items>
                                    <ComboBoxItem Content="1" />
                                    <ComboBoxItem Content="2" />
                                    <ComboBoxItem Content="3" />
                                </ComboBox.Items>
                            </ComboBox>
                        </DataTemplate>
                    </telerikGrid:GridViewColumn.CellTemplate>
                </telerikGrid:GridViewColumn>
            </telerikGrid:RadGridView.Columns>
        </telerikGrid:RadGridView>

C#
       private void RadGridView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            var clickedElement = e.OriginalSource as UIElement;
            if (clickedElement != null)
            {
                var row = clickedElement.ParentOfType<GridViewRow>();
                if (row != null)
                {
                    var combo = row.ChildrenOfType<ComboBox>().Where(c => c.Name == "MyCombo").FirstOrDefault();
                }
            }
        }

Greetings,
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
Amit Patel
Top achievements
Rank 1
answered on 21 Oct 2009, 07:58 PM
Thanks for the quick reply, really appreciate it!
0
Kjell
Top achievements
Rank 1
answered on 03 Jul 2010, 09:40 PM
Sorry to dig up an old thread but when I try the above, I get an error on :

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

the type or namespace "GridViewRow" could not be found.

Probably missing something easy/obvious, please help.
0
Kjell
Top achievements
Rank 1
answered on 03 Jul 2010, 10:04 PM
nevermind I just had to add

using

 

 

Telerik.Windows.Controls.GridView;

 

0
Rajesh
Top achievements
Rank 1
answered on 29 Aug 2011, 01:13 PM
Ok good example. But i am using Microsoft silverlight datagrid. Not teleric. So i am getting an error that "The type or namespace not found for "GridViewRow". Can u tell me any solution for this?
Tags
GridView
Asked by
Amit Patel
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Amit Patel
Top achievements
Rank 1
Kjell
Top achievements
Rank 1
Rajesh
Top achievements
Rank 1
Share this question
or