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

How to access Detail from Codebehing

11 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sarkis Matossian
Top achievements
Rank 1
Sarkis Matossian asked on 19 Aug 2009, 06:43 PM
I have a RadGridView in my Silverlight 3 application.  In the details view, I have some named controls (x:Name="TextBoxName").  I need to access this named control for the current row from the codebehind.  How do I do this?

Thanks.

11 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 20 Aug 2009, 04:34 PM
Hi Sarkis Matossian,

This could be easily done with our ChildrenOfType method. You could try something like:

// required namespaces  
// using Telerik.Windows.Controls.GridView;  
// using System.Linq;  
 
var currentRow = (GridViewRow)this.RadGridView1.ItemsControl.ItemsGenerator.ContainerFromItem(this.RadGridView1.CurrentRecord);  
var textBox = currentRow.ChildrenOfType<TextBox>().Where((element) => element.Name == "TextBoxName").First(); 

The ChildrenOfType method will return all children of a given type. Since we want a specific child we use the Where extension method to filter the original collection and only get the element that is named "TextBoxName".

Hope this helps.

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sarkis Matossian
Top achievements
Rank 1
answered on 20 Aug 2009, 04:47 PM
Thank you for your response.  Your code looks like exactly what I am looking for, however, it does not appear to work with the version that I am using.  We are developing using Silverlight 3. 

The "this.RadGridView1.CurrentRecord" indicates that it is deprecated, and I should use "CurrentItem" instead.  More importantly, the "currentRow.ChildrenOfType<>" gives an error that "ChildrenOfType<>" is not a method of GridViewRow.

Do you have an example that will work with this version?

Thanks.
0
Milan
Telerik team
answered on 20 Aug 2009, 05:29 PM
Hi Sarkis Matossian,

The ChildrenOfType method is in the "Telerik.Windows.Controls" namespace. I have missed to include it in the required namespaces. Sorry, my mistake. If you include a using for "Telerik.Windows.Controls" you should be able to use the method.

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sarkis Matossian
Top achievements
Rank 1
answered on 20 Aug 2009, 05:53 PM
That works.  Thank you.

Out of curiosity, since the "CurrentRecord" property of the RadGridView is deprecated, how would you achieve this using non-deprecated methods and properties?
0
Milan
Telerik team
answered on 21 Aug 2009, 01:56 PM
Hello Sarkis Matossian,

In our latest release (Q2 2009 Sp1) the ContainerFromItem method also accepts data item (not only data record) so once you update you will be able to use CurrentItem instead of CurrentRecord. In our latest service pack you will be able to use RadGridView.Items instead of RadGridView.Records.

Greetings,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Khurram Ilyas
Top achievements
Rank 1
answered on 17 Feb 2010, 01:06 PM
I am using the latest release and i am unable to fine the itemcontrol property in radgird view.
0
Vlad
Telerik team
answered on 17 Feb 2010, 01:52 PM
Hi Khurram Ilyas,

ItemsControl were obsolete and removed for Q3. You can use ItemContainerGenerator property of the grid instead.

Sincerely yours,
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.
0
Loretta Stokes
Top achievements
Rank 1
answered on 05 May 2010, 06:52 PM
I was using what was recommended in this article but after upgrading to Q1 2010 SP1 it no longer functions. I am trying to access a chart that is in the details row of my grid.

 Here's the code:

  var currentRow = (GridViewRow)this.dg.ItemContainerGenerator.ContainerFromItem(this.dg.CurrentItem);
  var chart = currentRow.ChildrenOfType<RadChart>().Where((element) => element.Name == _ChartIndexName).First();

I am getting an error that the Sequence contains no elements. I think the currentRow is not returning the GridViewRow. Right now it returns the POCO item. Do I need to call this a different way?
0
Rossen Hristov
Telerik team
answered on 10 May 2010, 02:17 PM
Hello Khurram Ilyas,

Getting that the sequence contains no elements, means that current row is fine. If it wasn't you would crash with a null reference exception. The exception you are getting simply states that there are not RadCharts inside the row and the call to .First() fails.

Do you have a RadChart as a child of the row you are testing?

I hope this helps.

In case it does not, we would like to ask you to send us a small dummy project and tell us what exactly are you expecting and trying to achieve.

All the best,
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:49 PM
Hello,

I'm not sure if this can help but in a previous post from me I've put an example that is working fine to access child elements inside a GridView. I had the same problem and this was I was using a tab control and the next element in child hierarchy was the tab control an not the child grid.

This is the right code that I use to access the child grid and works fine:

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(); 
 

Regards
Jose


0
Loretta Stokes
Top achievements
Rank 1
answered on 17 May 2010, 09:10 PM
I am working on putting together a project. I'll also try the suggestions listed as well.
Tags
GridView
Asked by
Sarkis Matossian
Top achievements
Rank 1
Answers by
Milan
Telerik team
Sarkis Matossian
Top achievements
Rank 1
Khurram Ilyas
Top achievements
Rank 1
Vlad
Telerik team
Loretta Stokes
Top achievements
Rank 1
Rossen Hristov
Telerik team
Jose
Top achievements
Rank 2
Share this question
or