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

Nested Radgridview find child control

1 Answer 195 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Animesh Singh
Top achievements
Rank 1
Animesh Singh asked on 19 Jul 2010, 09:47 AM
I am using Visual studio 2010 and Telerik controls for WPF Q1 2010 version.
I am using nested radgridview (detailsview), checkbox has been placed in inner radgridview, i am trying to find out the checkbox but undable to do so.

How to find controls in nested radgridview

please see below my code.

Refer the attached image, in order to understand the problem.

<Grid>

               

        <telerik:RadGridView Grid.Row="1" Grid.Column="0" AutoGenerateColumns="False" ShowGroupPanel="False" Name="grdPendingOrderDetail">

            <telerik:RadGridView.Columns>

                <telerik:GridViewToggleRowDetailsColumn></telerik:GridViewToggleRowDetailsColumn>

                <telerik:GridViewDataColumn Header="Customer Codes" DataMemberBinding="{Binding CustomerCodes}" ></telerik:GridViewDataColumn>

                <telerik:GridViewDataColumn Header="Created On" DataMemberBinding="{Binding CreatedOn}" ></telerik:GridViewDataColumn>

                <telerik:GridViewDataColumn Header="Modified On" DataMemberBinding="{Binding ModifiedOn}" ></telerik:GridViewDataColumn>

                <telerik:GridViewDataColumn>

                    <telerik:GridViewDataColumn.CellTemplate>

                        <DataTemplate>

                            <Button Content="Resume" Click="Button_Click" Tag="{Binding CustomerCodes}"></Button>

                        </DataTemplate>

                    </telerik:GridViewDataColumn.CellTemplate>

                </telerik:GridViewDataColumn>

            </telerik:RadGridView.Columns>

            <telerik:RadGridView.RowDetailsTemplate>

                <DataTemplate>

                    <Grid>

                        <telerik:RadGridView AutoGenerateColumns="False" ItemsSource="{Binding PendingOrderCategories}" ShowGroupPanel="False" Name="grdPendingOrderCategory">

                            <telerik:RadGridView.Columns>

                                <telerik:GridViewToggleRowDetailsColumn></telerik:GridViewToggleRowDetailsColumn>

                                <telerik:GridViewDataColumn Header="Category Name" DataMemberBinding="{Binding CategoryName}" ></telerik:GridViewDataColumn>

                            </telerik:RadGridView.Columns>

                            <telerik:RadGridView.RowDetailsTemplate>

                                <DataTemplate>

                                    <Grid>

                                        <telerik:RadGridView AutoGenerateColumns="False" IsFilteringAllowed="False" ShowGroupPanel="False" Name="grdPendingOrder" ItemsSource="{Binding PendingOrders}">

                                            <telerik:RadGridView.Columns>

                                                <telerik:GridViewToggleRowDetailsColumn></telerik:GridViewToggleRowDetailsColumn>

                                                <telerik:GridViewSelectColumn IsGroupable="True" ></telerik:GridViewSelectColumn>

                                                <telerik:GridViewDataColumn Header="Sales Order ID" DataMemberBinding="{Binding SalesOrderID}" ></telerik:GridViewDataColumn>

                                            </telerik:RadGridView.Columns>

                                            <telerik:RadGridView.RowDetailsTemplate>

                                                <DataTemplate>

                                                    <Grid>

                                                        <telerik:RadGridView AutoGenerateColumns="False" Name="grdOrderDetail" ItemsSource="{Binding OrderDetails}">

                                                            <telerik:RadGridView.Columns>

                                                                <telerik:GridViewDataColumn Header="Product Code" DataMemberBinding="{Binding ProductCode}" ></telerik:GridViewDataColumn>

                                                                <telerik:GridViewDataColumn Header="Customer Code" DataMemberBinding="{Binding CustomerCode}" ></telerik:GridViewDataColumn>

                                                                <telerik:GridViewDataColumn Header="Customer Name" DataMemberBinding="{Binding CustomerName}" ></telerik:GridViewDataColumn>

                                                                <telerik:GridViewDataColumn Header="Price" DataMemberBinding="{Binding Price}" ></telerik:GridViewDataColumn>

                                                                <telerik:GridViewDataColumn Header="Quantity" DataMemberBinding="{Binding OrderQty}" ></telerik:GridViewDataColumn>

                                                            </telerik:RadGridView.Columns>

                                                        </telerik:RadGridView>

                                                    </Grid>

                                                </DataTemplate>

                                            </telerik:RadGridView.RowDetailsTemplate>

                                        </telerik:RadGridView>

                                    </Grid>

                                </DataTemplate>

                            </telerik:RadGridView.RowDetailsTemplate>

 

                        </telerik:RadGridView>

                    </Grid>

                </DataTemplate>

            </telerik:RadGridView.RowDetailsTemplate>

        </telerik:RadGridView>

    </Grid>

 

private void Button_Click(object sender, RoutedEventArgs e)

        {

 

            Button btn = sender as Button;

            GridViewRow row = btn.ParentOfType<GridViewRow>();  //Row with CustomerName

            RadGridView grd = row.ChildrenOfType<RadGridView>()[0]; //Grid with category name

            GridViewDataControl grdVDC = grd as GridViewDataControl;

            string salesOrderIDs = "";

            foreach (GridViewRow rw in grdVDC.ChildrenOfType<GridViewRow>())  //foreach category name

            {

                RadGridView grdInner;

                GridViewDataControl grdVDCInner;               

                if (!(rw is GridViewNewRow))

                {

                    grdInner = rw.ChildrenOfType<RadGridView>()[0];

                    grdVDCInner = grdInner as GridViewDataControl;

                    foreach (GridViewRow rwInner in grdVDCInner.ChildrenOfType<GridViewRow>())  // foreach order in one category                

                    {

                        if (!(rwInner is GridViewNewRow))

                        {

                            bool select = (bool)((System.Windows.Controls.CheckBox)rwInner.Cells[1].Content).IsChecked;

                            if (select)

                            {

                                salesOrderIDs += ((System.Windows.Controls.TextBlock)rwInner.Cells[2].Content).Text;

                                salesOrderIDs += ",";

                                break;

                            }

                        }

                    }

                }

            }

        }

 

 

1 Answer, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 19 Jul 2010, 01:06 PM
Hi Animesh Singh,

 Have you tried calling rwInner.FindChildByType<CheckBox>?

Greetings,
Yavor Georgiev
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
Animesh Singh
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Share this question
or