/// Event handler for when cell content is clicked. Specifically, we are checking if the Administrator
/// checkbox state is changed and refreshing the grid so the un-necessary cells are disabled and
/// grayed-out (via the subsequent CellFormatting event).
private void OnCellContentClick(object sender, DataGridViewCellEventArgs e)
if (theGrid.Columns[e.ColumnIndex] != ColumnAdminCheckBox)
theGrid.EndEdit(); // VERY important call or the repaint doesn't happen until the cell loses focus.
/// Event handler for when cell content is formatted. Specifically, we are checking the state of the
/// Administrator checkbox and setting the ReadOnly and BackColor of the cells that do not apply when
/// user is an administrator.
void OnCellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
// Only update certain columns
DataGridViewColumn column = theGrid.Columns[e.ColumnIndex];
if (column != ColumnA && column != ColumnB &&
column != ColumnC)
object obj = theGrid[theGrid.Columns.IndexOf(ColumnAdminCheckBox), e.RowIndex].Value;
if (obj == null || obj.GetType() != typeof(bool))
bool admin = (bool)obj;
theGrid[e.ColumnIndex, e.RowIndex].ReadOnly = admin;
e.CellStyle.BackColor = (admin ? theGrid.BackgroundColor : Color.White);
This is a dumping ground of software development topics that I've run across and found interesting (mainly .NET development). Many topics are covered more thoroughly in other places, and much of the information is gleaned from other places, and I'll try to credit those sources when possible.