I'm using the standard RadGridVeiw events to set various cell states such as enabled. Everything works fine as long as the grid doesn't have a scroll bar. Here is the code.
I'm finding that on this line
if (row.Cells[e.ColumnIndex].CellElement != null) CellElement is null and is that last row in view when the grid loads. So my code below only works for rows in view.
Let me state exactly what I'm trying to do. If nothing else please help me find the correct solution.
I have a Winforms RadGridView table with GridViewCheckBoxes in a column. When a user selects a checkbox in a row i want all the rest of the checkboxes in the other rows to be disabled. When the user unchecks the checkboxed row I want all checkboxes in other rows to be enabled. It's simple, only one checkbox in a row can be selected.
public bool HandleCellValueChanged(RadGridView matrixRadGrid, GridViewCellEventArgs e, MatrixPickerPresenter matrixPresenter, RadGridView measureGrid)
{
bool IsValidSelection = false;
if (reportType == CustomReportTypes.Matrix || reportType == CustomReportTypes.MatrixRowWithHistory || reportType == CustomReportTypes.MatrixWithHistory)
{
if (e.Column.HeaderText == "Selected")
{
measureGrid.DataSource =
null;
if (matrixPresenter.Measures.Count > 0)
{
measureGrid.Enabled =
true;
measureGrid.DataSource = matrixPresenter.Measures;
try
{
var displayRow =
measureGrid.Rows.Where(row => ((
ReportMeasure)row.DataBoundItem).IsDisplayMeasure).FirstOrDefault();
if (displayRow != null)
{
// The Display Measure must be in view for the RowFormatting event to fire and the user needs to know what the Display Measure is at the start.
measureGrid.GridElement.ScrollToRow(displayRow);
}
}
catch
{
// Do nothing: No need to end the world just because the Display Measure isn't in view.
;
}
}
else
{
measureGrid.Enabled =
false;
}
IsValidSelection = measureGrid.Enabled;
var selectedReportItem = e.Row.DataBoundItem as ReportMatrix;
if (selectedReportItem != null)
{
bool enableOtherSelectedCheckboxes = true;
if (selectedReportItem.Selected)
{
enableOtherSelectedCheckboxes =
false;
IsValidSelection =
true;
}
for (int index = 0; index < matrixRadGrid.Rows.Count; index++)
{
var row = matrixRadGrid.Rows[index];
if (e.RowIndex == index)
{
if (!selectedReportItem.Selected)
{
selectedReportItem.MatrixParameter = (
int)MatrixParameterTypes.None;
e.Row.Cells[e.ColumnIndex + 1].Value = (
int)MatrixParameterTypes.None;
}
continue;
}
matrixRadGrid.GridElement.ScrollToRow(row);
if (row.Cells[e.ColumnIndex].CellElement != null)
{
row.Cells[e.ColumnIndex].CellElement.Enabled = enableOtherSelectedCheckboxes;
}
}
}
}
else if (e.Column.HeaderText == "Runtime Parameter")
{
bool setEnabled = true;
var reportMatrix = e.Row.DataBoundItem as ReportMatrix;
if (reportMatrix != null && reportMatrix.Selected)
{
setEnabled =
false;
IsValidSelection =
true;
measureGrid.Enabled =
true;
}
for (int index = 0; index < matrixRadGrid.Rows.Count; index++)
{
var row = matrixRadGrid.Rows[index];
if (e.RowIndex == index)
{
continue;
}
row.Cells[e.ColumnIndex].CellElement.Enabled = setEnabled;
}
}
}
return IsValidSelection;
}
}