2009-05-08 10 views
0

CheckBoxColumnがチェックされている行でremarkイベントにこのイベントを使用していますので、「Value」プロパティを使用して同じ行の現在のセル[6]値を「プログラムで」置き換えますデフォルトでは "readOnly"プロパティは= "true"です。DataGridViewCellEventArgsがDataGridViewCellの現在の値を変更する方法を教えてください。

DataGridView1.DataSourceは、LINQ2SQLクエリから取得されます。

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

私はDataSourceで実際のオブジェクト/行を見つけてそこのブール値を反転し、グリッドを再バインドします。次に、CellFormattingイベントでBackColorを設定できます。

関連する問題