Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
I want to skip for/foreach by using linq for below code-
'For Each row In uxDataGridView.Rows
                '    If Not row.Cells(0).ReadOnly Then
                '        row.Cells(0).Value = True
                '    End If
                'Next
Posted
Comments
Member 9111713 12-Dec-12 7:29am    
Please help me ASAP.

I think you need to understand what Linq under the hood really does...

To clear this a little bit to you: Linq is just syntactic sugar, this means under the hood linq uses
Enumerators over its datasources.. And that anyway will end in an foreach loop.
I guess now i know what you want to achieve, it seems you just want a performant way to edit the cells that are accessible.?!

im afraid you dont have other choices as to do as i mentioned, or to rethink the whole logic of your table if
you come up to iterate over 4000! rows...
 
Share this answer
 
maybe this works...

C#
uxDataGrid.Rows.Where(c => c.Cells[0].ReadOnly == false).ForEach(c => c.Cells[0] = true);


Mark as answer if it worked!

regards Patrick
 
Share this answer
 
v4
Comments
Member 9111713 12-Dec-12 8:09am    
Hi Patrick,
Thanks for reply..but I want to do this because of the performance issue (to select first cell of each row if 4000 rows in grid takes 10-15 second) and I tried the below code also but not useful.
Dim rowsList = (From row In uxDataGridView.Rows Where Not row.Cells(0).ReadOnly Select row).ToList()
rowsList.ForEach(Sub(p As DataGridViewRow)
p.Cells(0).Value = True
End Sub)

I just don't want to add foreach in my code. Please reply if someone has any other solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900