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

RadGridView1.ChildrenOfType<GridViewRowItem>()

11 Answers 430 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Orit
Top achievements
Rank 1
Orit asked on 11 Jan 2010, 08:03 AM
Hello

I want to search for a value in one of the columns in my grid and then select the row
I used this code to run on the items
foreach (GridViewRowItem griParent in RadGridView1.ChildrenOfType<GridViewRowItem>())  
                    {  
                        if (griParent.DataItem != null)  
                        {  
                            if ((griParent.DataItem as DataRowView).Row["ActivityName"].ToString().Contains(sSearch))  
                            {  
                                gvriParent.Add(griParent);   
                            }           
                        }  
                    }  
..........  
 
if (iParentSearch < gvriParent.Count)  
                {  
                    if ((gvriParent[iParentSearch] as GridViewExpandableRow) == null && ((gvriParent[iParentSearch].ParentOfType<GridViewExpandableRow>()))!=null)  
                    {  
                        ((gvriParent[iParentSearch].ParentOfType<GridViewExpandableRow>())).IsExpanded = true;  
                    }  
                    gvriParent[iParentSearch].IsSelected = true;  
                    this.RadGridView1.BringDataItemIntoView(gvriParent[iParentSearch]);  
                    iParentSearch++;  
                }  
...... 

the problem is
that if there is a scroll in my grid
the "foreach (GridViewRowItem griParent in RadGridView1.ChildrenOfType<GridViewRowItem>())   "
does not get the rows that are not shown in the screen

by the way
I use - this.RadGridView1.BringDataItemIntoView
but it looks like nothing happen

Thanks

11 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Jan 2010, 08:08 AM
Hello Orit,

You can achieve your goal using ItemContainerGenerator instead:
http://demos.telerik.com/wpf/?GridView/Disabled

Best wishes,
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
Orit
Top achievements
Rank 1
answered on 11 Jan 2010, 09:13 AM
Hi

Thanks for the quick reply
I tried to use ItemContainerGenerator 
but I get an error under it

foreach (object item in RadGridView1.Items)  
                   {  
                       GridViewRow griParent = RadGridView1.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow;  
                        

Error 200 'Telerik.Windows.Controls.RadGridView' does not contain a definition for 'ItemContainerGenerator' and no extension method 'ItemContainerGenerator' accepting a first argument of type 'Telerik.Windows.Controls.RadGridView' could be found (are you missing a using directive or an assembly reference?) 

(I still use Q2
does it force me to upgrade now?)


0
Vlad
Telerik team
answered on 11 Jan 2010, 11:40 AM
Hello Orit,

With Q2 you can use ItemsControl.ItemsGenerator instead ItemContainerGenerator.

Sincerely yours,
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
Orit
Top achievements
Rank 1
answered on 11 Jan 2010, 11:56 AM

This is my code

 foreach (object item in RadGridView1.Items)  
 {  
       GridViewRow griParent = RadGridView1.ItemsControl.ItemsGenerator.ContainerFromItem(item) as GridViewRow;  
                        

the first rows are OK
but when it get the rows that are not in the screen
 the griParent  get null
0
Vlad
Telerik team
answered on 11 Jan 2010, 01:55 PM
Hi Orit,

I've attached small example to illustrate you how to achieve this using a bit different approach.

Best wishes,
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
Orit
Top achievements
Rank 1
answered on 12 Jan 2010, 07:54 AM
Thank You for the example
it looks fine
but there is one thing
I don't want to sellect all the rows at once
I have a "next" button
and in each click I want to move to the next result
so the
foreach (var item in items)  
                   {  
                       RadGridView1.SelectedItems.Add(item);  
                   } 
is not good for me
I need a way to select each time one row
something like
RadGridView1.SelectedItems.Add(item[index])

is there a way to do it?
0
Orit
Top achievements
Rank 1
answered on 12 Jan 2010, 08:05 AM
I forgot a very important thing!
my grid is hierarchy
I notice that when I search the grid in this way

foreach (GridViewRowItem griParent in RadGridView1.ChildrenOfType<GridViewRowItem>())

 

it also get the children
but when I use

 

var

 

items = RadGridView1.Items.OfType<DataRowView>().Where(i => i.Row["ActivityName"].ToString().Contains(sSearch));
it doesnot get the children

 

0
Orit
Top achievements
Rank 1
answered on 13 Jan 2010, 07:32 AM
Hello

I'm still waiting for your answer
do you have any idea for me?

Thanks
0
Vlad
Telerik team
answered on 13 Jan 2010, 08:09 AM
Hello Orit,

This line:
var items = RadGridView1.Items.OfType<MyObject>().Where(i => i.Name.Contains(TextBox1.Text));

will get all items for this criteria however you can use other extension methods to get desired item. For example the first item will be:

var item = RadGridView1.Items.OfType<MyObject>().Where(i => i.Name.Contains(TextBox1.Text)).FirstOrDefault();

Generally ChildrenOfType will loop the visual tree elements recursively to find desired element type however Items is a flat collection of the items bound to the grid.

Best wishes,
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
Orit
Top achievements
Rank 1
answered on 14 Jan 2010, 10:14 AM
Sorry
but I didn't underatand
what is the way you suggest
to find all the items parent and children
can you please senr some rows with the code
Thanks
0
Orit
Top achievements
Rank 1
answered on 18 Jan 2010, 08:14 AM
I am still waiting for your answer
Thanks

Tags
GridView
Asked by
Orit
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Orit
Top achievements
Rank 1
Share this question
or