tags:

views:

13

answers:

0

Hi, in CellFormatting event handler of the my DataGridView object, i'm changing the CellStyle attribute as

e.CellStyle.BackColor = Color.LightGray;

this shows up fine in the UI.

When I tried to get the BackColor of the cell in CellMouseDown event, the object doesn't show up the Color.LightGray color... I tried all possible combinations. code snippet added...

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
  DataGridView dgv = sender as DataGridView;

  if (e.RowIndex == -1) return;
  DataGridViewRow dgvr = dgv.Rows[e.RowIndex] as DataGridViewRow;

  MyDataRow dr = (dgvr.DataBoundItem as DataRowView).Row as MyDataRow;

  if (!dr.Enabled)
  {
   e.CellStyle.BackColor = Color.LightGray;
  }
}

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
 DataGridView dgv = sender as DataGridView;
 if (dgv.SelectedRows == null) ;

 if (e.RowIndex == -1) return;
 DataGridViewRow dgvr = dgv.Rows[e.RowIndex] as DataGridViewRow;

 if (dgvr.InheritedStyle.BackColor == Color.LightGray) ;
 if (dgvr.Cells[e.ColumnIndex].InheritedStyle.BackColor == Color.LightGray) ;
 if (dgvr.Cells[e.ColumnIndex].Style.BackColor == Color.LightGray) ;
 if (dgvr.Cells[e.ColumnIndex].Style.SelectionBackColor == Color.LightGray) ;
}

This is killing me... please help...

Regards ArunDhaJ