Click here to Skip to main content
15,747,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have been browsing the web to search for a direct LINQ query that allows me to get all the cells that contains a specific values.

the one to get the rows is:

(from DataRow r in dtableInput.Rows
                                        where r.ItemArray.Any(c => c.ToString().Contains("Keyword"))
                                        select r).ToArray();

I need to get the position of each cell. Can anyone help?

Thanks in advance

This is what you should use. Its LINQ support for legacy ADO stuff, like DataTable(s)/DataView(s)/DataRow(s) etc etc

And here is an example of its usage :
Share this answer
Mehdi_S 7-Oct-13 5:36am    
yeah That's what I used for the example above but my need is something with LINQ that should be similar to:
(from DataRow r in dtableInput.Rows
(from DataCell c (or whatever) in r.Cells
where c.Value.Contains("Keyword"))).select c).ToArray();

This kind of query does not work actually. The only solution I had is to query the rows with linq and then query the cells for each selected data row. I wanted to optimize that :)
Actually I had to brows rows then browse columns for each rows. This solution allowed me to get the index of the rows and columns using Rows.IndexOf and Columns.IndexOf.

I'm not sure this is the best implementation but it helps for now.
Thank you all
Share this answer

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