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

Access RadGridView Rows Collection from code behind

5 Answers 155 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jay
Top achievements
Rank 1
jay asked on 12 Sep 2010, 11:05 PM

Hi. 

I have this piece of code that works just great. I have a hierarchical RadgridView and this code block helps to determine whether an employee has any subordinates.
I recently moved to MVVM and I don't want to create another instance of my domaincontext (ctx) in my code behind.
I would rather access my RadGridView's rows collection directly and replace the [emp in (IEnumerable<vEmployee>)ctx.vEmployees] 
bit with something like [emp in this.RadGridView1.Rows]

Some help will be appreciated.

Thanks!
J


 private bool HasSubordinates(vEmployee employee)

        {       

            return

            (from emp in (IEnumerable<vEmployee>)ctx.vEmployees

             where emp.ReportsToID == employee.EmployeeID

             select emp).Any();

           

        }



5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 13 Sep 2010, 07:08 AM
Hi,

 You can use Items collection to achieve your goal. 

All the best,
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
sonam
Top achievements
Rank 1
answered on 23 Feb 2011, 09:36 AM
hi,
i have a radgridview and i bound it with the list <object> collection , i have just direct bind it with the list by putting autogenerate columns to true.so that there are two textcolumn and three checkbox column made up in the grid as per the object binded with the list.
now i want to check  all the checkbox columns for each rows on a button click in such a way that for each row at least one checkbox out of the three must be checked. but the problem is that in my silverlight project i am unable to access rows of radgridview individualy. please help me in acheiving this scenario.   
0
Maya
Telerik team
answered on 23 Feb 2011, 09:46 AM
Hi sonam,

The recommended approach would be to expose separate boolean properties for those CheckBox-es, iterate as mentioned previously through the Items collection and verify whether each item has at least one property set to "True".
Furthermore, another possible approach may be to handle the RowValidating/ RowValidated event and check whether after editing each item, it contains the required number of "True" values.

 

Greetings,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
sonam
Top achievements
Rank 1
answered on 23 Feb 2011, 10:31 AM
but i dont want to create properties for the checkboxes. what i want is to read every row of my radgridview and then further need to go on every checkbox columms of that row . 
0
Maya
Telerik team
answered on 23 Feb 2011, 10:39 AM
Hello sonam,

If you do not want to expose properties bound to the IsChecked property of the CheckBox-es, you risk that the their state (checked/ unchecked) may be lost during scrolling. As by default the virtualization of the grid is turned on, the visual elements will be recycled on scrolling, which may lead to loss of data in case you count on the values of those elements. That is why my recommendation is to expose boolean properties that will ensure you get the correct values for each item. 

 

All the best,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
jay
Top achievements
Rank 1
Answers by
Vlad
Telerik team
sonam
Top achievements
Rank 1
Maya
Telerik team
Share this question
or