I have a check box field in my grid that I want to be mutually exclussive. That is, I want only one or zero rows to have a value of true for that check box at any point in time. I tried code that changes the check box value of every row to false, but this is very slow. So I thought I would keep a variable that stores the last row index that had a value of true for the check box field. I have (at least) one group set up for the grid. I am trying to store the current row index when the grid is first loaded using the following code:
foreach (GridViewRowInfo _row in employeesGrid.Rows) |
{ |
foreach (GridViewRowInfo _row2 in _row.Rows) |
{ |
if (_row2.Cells["InitialAssignee"].Value != null && (bool)_row2.Cells["InitialAssignee"].Value == true) |
{ |
curInitialAssignee = employeesGrid.Rows.IndexOf(_row2); |
} |
} |
} |
This code assumes that there is one level of grouping. The problem is that curInitialAssignee is always set to -1. I'm not sure why I can't get the row index of _row2.
Once the above is working, I have code in the ValueChanging event that will set the value of the InitialAssignee column to false for the row that corresponds to curInitialAssignee. Followed by a line that changes curInitialAssignee to the new current row.
Also, I want to ensure that this row index remains valid even if the data is sorted differently, or a grouping is added or removed at run time.
Thanks,
Eric.