views:

665

answers:

1

Hi SO People!, I'm using this event for remark the row when the CheckBoxColumn had been checked, so additionally I want to replace "programatically", the current cell[6] value from the same Row using the "Value" property but it fails cause by default the "readOnly" property is = "true".

The DataGridView1.DataSource is retrieved from a LINQ2SQL Query.

void updateStyle_DataGridViewCellEventArgs(object sender, DataGridViewCellEventArgs e)
{
     if (e.RowIndex == -1)
         return;
     else
     {
        DataGridView dgv = sender as DataGridView;
        int vCHK = e.ColumnIndex;
        if (vCHK != 0)
            return;
        else
        {
            DataGridViewCheckBoxCell temp = (DataGridViewCheckBoxCell)dgv.Rows[e.RowIndex].Cells[0];
            if ((bool)temp.EditedFormattedValue == true)
            {
                DataGridViewTextBoxCell xrow = (DataGridViewTextBoxCell)dgv.Rows[e.RowIndex].Cells[6];
                xrow.ReadOnly = false;
                xrow.Value = "P";
                xrow.OwningRow.DefaultCellStyle.BackColor = Color.Wheat;
            }
            else
            {
                temp.OwningRow.DefaultCellStyle.BackColor = Color.White;
            }
        }
    }
}
+1  A: 

I'd find the actual object/row in the DataSource, flip the boolean there, and rebind the grid. Then you can set the BackColor in the CellFormatting event.

Chris Doggett