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

Access to row in radgridview inside of RowDetailsTemplate

4 Answers 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 2
Jose asked on 05 May 2010, 06:19 PM
Hi,

How can I access to a SelectedItem property of a radgridview inside another radgridview?
I want to launch a window with data values of the current record of the child grid but I don't know how to access this record from code behind.
Thanks a lot
Jose

4 Answers, 1 is accepted

Sort by
0
Jose
Top achievements
Rank 2
answered on 05 May 2010, 07:46 PM
Just for more information... I'm using the same example that Telerik SL demo. Tab control inside RadGridView, two of the tabs are for grids.
Regards
0
Rossen Hristov
Telerik team
answered on 10 May 2010, 02:09 PM
Hi Jose,

You can find a RadGridView down the visual tree by using the ChildrenOfType<T> extension method. Conversely, you can find a RadGridView up the visual tree by using the ParentOfType<T> extension method.

These two methods are extension methods for the UIElement class. So if you have a GridViewRow for example, you can write:

row.ChildrenOfType<RadGridView>()[0] and this will return the details grid that is inside the row details of the row.

Both of these methods are inside the Telerik.Windows.Controls namespace, so make sure you have a using statement.

I hope this helps.

Sincerely yours,
Ross
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.
0
Jose
Top achievements
Rank 2
answered on 10 May 2010, 03:39 PM
Hi Ross,

Thanks a lot for your help.

I've this code and it works fine. I can access to row elements in child grid.
I can edit and add new records to the child datagrid, but I'm unable to delete a record.

This is the code that I'm using (probably I'm wrong because I'm very new to SL and RIA):

 
        private void deleteContactButton_Click(object sender, RoutedEventArgs e) 
        { 
            CustomerContact currentCustomerContact = new CustomerContact(); 
 
            var currentRow = (GridViewRow)this.customersRadGridView.ItemContainerGenerator.ContainerFromItem(this.customersRadGridView.CurrentItem); 
            var currentTab = currentRow.ChildrenOfType<RadTabControl>().Where((element) => element.Name == "customerRadTabControl").First(); 
            var customerContactGrid = currentTab.ChildrenOfType<RadGridView>().Where((element) => element.Name == "customerContactsRadGridView").First(); 
 
            currentCustomerContact = (CustomerContact)customerContactGrid.SelectedItem; 
 
            if (currentCustomerContact != null) 
            { 
                string confirmText = "You are going to delete the customer\n(" + currentCustomerContact.FirstName + " " + currentCustomerContact.LastName + 
                                     ")\n\nAre you sure?"; 
                RadWindow.Confirm(confirmText, new EventHandler<WindowClosedEventArgs>(OnConfirmDeleteCustomerContactClosed)); 
            } 
        } 
 
        private void OnConfirmDeleteCustomerContactClosed(object sender, WindowClosedEventArgs e) 
        { 
            if (e.DialogResult == true) 
            { 
                var currentRow = (GridViewRow)this.customersRadGridView.ItemContainerGenerator.ContainerFromItem(this.customersRadGridView.CurrentItem); 
                var currentTab = currentRow.ChildrenOfType<RadTabControl>().Where((element) => element.Name == "customerRadTabControl").First(); 
                var customerContactGrid = currentTab.ChildrenOfType<RadGridView>().Where((element) => element.Name == "customerContactsRadGridView").First(); 
 
                Customer currentCustomer = (Customer)customersRadGridView.SelectedItem; 
                CustomerContact currentCustomerContact = (CustomerContact)customerContactGrid.SelectedItem; 
                currentCustomer.CustomerContacts.Remove(currentCustomerContact); 
 
                this.customerDomainDataSource.SubmitChanges(); 
                //contactGrid.Rebind(); 
            } 
        } 
 

I'm receiving an error: "An error occurred while submitting changes on the DomainContext..."
Any idea what I'm doing wrong?

Thanks a lot in advanced
Jose
0
Rossen Hristov
Telerik team
answered on 11 May 2010, 10:58 AM
Hello Jose,

Unfortunately, we do not know what is going wrong. You might need to debug your project in order to see what is going wrong. See what the exception is saying. Does it say why there is an error when submitting the changes?

Are the customers you are trying to delete non-null, existing, and ok, etc.?

If you remove RadGridView alltogether and try to delete something (hard-coded) from the DomainDataSorce on a button click -- does the same error occur?

For example, if you do this with a hard-coded customer and customer contract:

Customer currentCustomer = <<your customer here>>;        
CustomerContact currentCustomerContact = <<the contract>>;                        currentCustomer.CustomerContacts.Remove(currentCustomerContact);        
this.customerDomainDataSource.SubmitChanges();        
                            
Does the same error occur? What does it say?

Since this is an exception thrown by the DomainDataSource, it might also be a good idea to post a question on the Microsoft forums. Just an idea.

We hope this helps.

Best wishes,
Ross
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
Jose
Top achievements
Rank 2
Answers by
Jose
Top achievements
Rank 2
Rossen Hristov
Telerik team
Share this question
or