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;
}
}
Private Sub RadGridView1_ChildViewExpanding(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.ChildViewExpandingEventArgs) Handles RadGridView1.ChildViewExpanding 'RadGridView1.Templates.GetTemplateByCaption(e.ParentRow.ActiveView.ViewTemplate.Caption) Dim stemplate As String If e.IsExpanded = False Then For Each row As GridViewRowInfo In RadGridView1.Rows If (row.IsExpanded = True) Then stemplate = DirectCast(row, Telerik.WinControls.UI.GridViewHierarchyRowInfo).ActiveView.ViewTemplate.Caption Exit For End If Next End If End SubgridViewMaskBoxColumn1.FieldName = "LSD";gridViewMaskBoxColumn1.HeaderText = "ll-ss-ttt-rr-mm";gridViewMaskBoxColumn1.Mask = "00\\-00\\-000\\-00\\-\\W0";gridViewMaskBoxColumn1.MaskType = Telerik.WinControls.UI.MaskType.Standard;gridViewMaskBoxColumn1.Name = "LSDM";gridViewMaskBoxColumn1.Width = 120;