I have a DataGridView similar to the one below:
ID Name Data1 Data2
1 MM X 1000
2 ST Y 1000
3 EC Z 1000
4 JT T 1000
I also have a list of row indices that are important to me.
List<int> myList = new List<int>();
myList.Add(1);
myList.Add(2);
Now what I want to do is grab the values from the Data1 column in my DataGridView that corresponds to those row indices. So what I am looking to get out (in this example) is some datatype which contains “Y” and “Z”.
I don’t want to iterate over the DataGridView because I have a large sample of data there. Is there a way to do this with LINQ? I’m still a LINQ beginner.
Use the
Enumerable.Selectmethod something like this:This code assumes that a reference to your
DataGridViewis stored in the variabledata.