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

[Solved] select rows from code

3 Answers 121 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
JungTae
Top achievements
Rank 1
JungTae asked on 13 Oct 2010, 09:17 PM
Hello telerik team, I am trying to do something like


 foreach(GridViewRow row in myTelerikRadGridView.Rows)
{
    /*code*/
}

but there it's a property for selecting rows. I am using  .NET 3.5 SP1 if that helps you find a solution for me

3 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 14 Oct 2010, 07:44 AM
Hello JungTae,

You may use the property of GridViewRow - IsSelected. All rows of the grid can be found either by the extension method ChildrenOfType<GridViewRow>() or using the ItemContainerGenerator of the grid.

//Option 1:
var rows = this.clubsGrid.ChildrenOfType<GridViewRow>();
 
foreach (GridViewRow row in rows)
{
    row.IsSelected = true;
}
//Option 2:
foreach (Club item in this.clubsGrid.Items)
{
    (this.clubsGrid.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow).IsSelected = true;
}

//Club is the type of the items inside the grid in this case.

However, if you need more than one rows to be selected, you need to set the SelectionMode property to either "Extended" or "Multiple". 

 

Kind regards,
Maya
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
JungTae
Top achievements
Rank 1
answered on 14 Oct 2010, 02:41 PM
Option #1 did not work because my intellisense did not show ChildrenOfType property.
Options #2 did workout great though, thanks for your help Maya!
0
Maya
Telerik team
answered on 14 Oct 2010, 02:44 PM
Hello JungTae,

I am glad that the proposed solution worked for your case. As for the first option, you need to add reference to Telerik.Windows.Controls (using Telerik.Windows.Controls;) in the class where you want to use the ChildrenOfType<> method. You may find further reference for this method in this blog post.
 

Greetings,
Maya
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
JungTae
Top achievements
Rank 1
Answers by
Maya
Telerik team
JungTae
Top achievements
Rank 1
Share this question
or