If you have a row with more than one checkbox it can be a little difficult reading each CheckState into separate variables. For example, let's say you have a sheet with three columns: ProductID, BackRelieved and EndMatched. BackRelieved and EndMatched are checkboxes. If you read each row, BackRelieved will be sheet.CheckBoxes[0].CheckState and EndMatched will be sheet.CheckBoxes[1].CheckState. Then the next row will be BackRelieved sheet.CheckBoxes[2].CheckState and EndMatched sheet.CheckBoxes[3].CheckState. So if you have 50 rows, you will have 100 checkbox items. To separate each checkbox on the row as you iterate through the sheet, use a separate counter (j) instead of the sheet row count (i). Then you can increment the checkbox counter (j) for each checkbox in the row.
- Code: Select all
int j = 0; // for checkbox counter
for (int i = 1; i < sheet.Rows.Length; i++)
{
string ProductID = sheet.Rows[i].Columns[0].DisplayedText;
bool BackRelieved = false;
if (sheet.CheckBoxes[j].CheckState.ToString() == "Checked")
BackRelieved = true;
j = j + 1;
bool EndMatched = false;
if (sheet.CheckBoxes[j].CheckState.ToString() == "Checked")
EndMatched = true;
j = j + 1;
}