0
votes

Ok so i have a lil function that will get a value from a field in each row of a datagridview.......... then look at what the value is and count an according increment.

heres the code so far:

    private void countParetoQty(int top, int tmid, int bmid, int bot )
    {
        //bunch of Ifs to count a record thats certain pareto

        foreach(DataGridViewRow row in dataGridView1)
        {
            if(//current row @ pareto <=50)
            {
                //top 50
                top++;
            }
            else 
                if()
                {
                    //50-100
                    tmid++;
                }
                else
                    if()
                    {
                        //100-200
                        bmid++;
                    }
                    else
                    {
                        //its over 200!!!!!!!!!!!!!!
                        bot++;
                    }
        }

as you can see i need to check the fields value "Pareto" on each row and cycle through afew If statements to increment the correct int. I need to know how i get the value im looking for an cycle through. Im thinking along the lines of foreach loop then conditioning by the current rows column.value? Many thanks in advance!

2

2 Answers

1
votes

You can access a cell value as following:

row.Cells["FiledName"].Value

or by index

row.Cells[0].Value
1
votes

You can get the value of the Pareto Column like this:

  int testValue = Row.Cells["Pareto"].Value;

Given that you have the row already, and that pareto is an integer.

I might also use a switch instead of nested ifs.