0

One column of my DataGridView contains a number of different values.

For example:

columnName
10
21
23
25
12
14
16
28
30
29
36
47
56
65
78
89
96
121
126
21
132
55
16
... etc

Here I need to separate the values which lies between the range 0-30, 30-60, 60-90.

var sector1 = "no.of values lies between 0-30";
var sector2 = "no.of values lies between 30-60";
var sector3 = "no.of values lies between 60-90";
var sector4 = "no.of values lies between 90-120";

Can any one suggest the syntax to find the count of rows between two ranges?

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
Vigna
  • 113
  • 1
  • 5
  • 13
  • I have edited your title. Please do not include information about a language used in a question title unless it wouldn't make sense without it. Tags serve this purpose. Also see, ["Should questions include “tags” in their titles?"](http://meta.stackoverflow.com/q/19190/193440), where the consensus is "no, they should not – chridam Jun 17 '14 at 10:08

1 Answers1

1

I would try something like this:

var values = datagridview.Rows
    .Cast<DataGridViewRow>()
    .Select(x => (int)x.Cells[column].Value);

var sector1 = values.Count(x => x >= 0 && x < 30);
[...]
Joanvo
  • 5,677
  • 2
  • 25
  • 35
  • i tried this,'try { var values = dataGridView1.Rows.Cast().Select(x => (int)x.Cells[columnName].Value); var sector1 = values.Count(x => x >= 0 && x < 30); var sector2 = values.Count(x => x >= 30 && x < 60); var sector3 = values.Count(x => x >= 60 && x < 90); var sector4 = values.Count(x => x >= 90 && x < 120); [...] MessageBox.Show(sector1.ToString()); [...] } catch { MessageBox.Show("ERROR"); }'.... but i'm getting error message only – Vigna Jun 18 '14 at 05:44