Formatting a single datagridview cell???
C#
2
Posts
2
Posters
0
Views
1
Watching
-
Is it possible to format only a few datagridview cells? Please help, thanks!
-
Is it possible to format only a few datagridview cells? Please help, thanks!
I'm not sure of the extent of formatting you plan on doing...but here is what I've done:
private void RowPrePaint( object sender, DataGridViewRowPrePaintEventArgs e ) { if ( ( ( DataGridView )sender ).Name.StartsWith( "detail" ) ) return; DataGridViewCell cell = viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "BatchSelectColumn" \]; bool ThisRowSelected = false; if (cell.Value != null) { ThisRowSelected = cell.Value == DBNull.Value ? false : (bool)cell.Value; } ElementState rowState = states\[ new Guid(viewer.BatchGrid.Rows\[e.RowIndex\].Cells\["batchGuid"\].Value.ToString()) \]; if ( rowState.InvalidDate) viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "dateReceived" \].Style.BackColor = Color.LightCoral; else viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "dateReceived" \].Style.BackColor = ThisRowSelected ? Color.LightSteelBlue : SystemColors.Info; if ( rowState.OutOfSequence ) viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "batchNumber" \].Style.BackColor = Color.LightCoral; else viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "batchNumber" \].Style.BackColor = ThisRowSelected ? Color.LightSteelBlue : SystemColors.Info; if ( rowState.AmountOutOfBalance ) viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "dollarAmount" \].Style.BackColor = Color.LightCoral; else viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "dollarAmount" \].Style.BackColor = ThisRowSelected ? Color.LightSteelBlue : SystemColors.Info; if ( rowState.CountOutOfBalance ) viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "formCount" \].Style.BackColor = Color.LightCoral; else viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "formCount" \].Style.BackColor = ThisRowSelected ? Color.LightSteelBlue : SystemColors.Info; if ( ThisRowSelected ) viewer.BatchGrid.Rows\[ e.RowIndex \].DefaultCellStyle.BackColor = Color.LightSteelBlue; else viewer.BatchGrid.Rows\[ e.RowIndex \].DefaultCellStyle.BackColor = SystemColors.Info; }