Get index of Rows with checked boxes and convert to integer array

Viewed 64

I have a datagrid with data in the first few columns and a checkbox in the last column to the right. The data columns have checkboxes that can only be selected (2) at a time indicating the input data. When data is changed in the checked rows the remaining rows are updated with calculated output from the input data rows. Depending on which (2) rows are checked a sequence for calculating the remaining rows is assigned. I'm struggling with how to capture the (2) rows selected and assign a sequence to it. There are (6) rows in total and any combination of (2) can be selected. Any help or direction would be greatly appreciated.

    private void dgvParameters_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {

    //Get index of Rows with boxes checked in Column [5] and assign an integer array sequence
    //Ex: if Rows 1 & 3 are selected then int sequence = new int[6] {0,5,2,4,6};
    //Ex: if Rows 1 & 2 are slected then int sequence = new int[2] {0,3,7};

            for (int i = 0; i < sequence.Length; i++)
            {
                switch (sequence[i])
                {
                    case 0: 
                        //Do calculation for input from row 0 to update other rows
                        break;
                    case 1:
                        //Do calculation for input from row 1 to update other rows
                        break;
                    ...
                    case 7:
                        //Do calculation for input from row 7 to update other rows
                    default:
                        break;
                }
            }
    }

Here is some clarification on the int array portion:

//Formulas f() for calculation data values:
Row 1 = a = f(c,d)
Row 2 = b = f(a,d)
Row 3 = c = f(a,b)
Row 4 = d = f(b,c)

//EX: if Row 1 & 2 selected then use the values in these cells to solve for Row 3 & 4
//sequences have to be in a particular order to update the formulas correctly.
if Rows Selected = 1 & 2 then sequence = {3 ,4} //Calculate Rows 3 & 4 
if Rows Selected = 3 & 4 then sequence = {1, 2}
if Rows Selected = 1 & 4 then sequence = {2, 3}
0 Answers
Related