就写在 CurrentCellChanged事件中就ok了; 
 

//锁定的行,这个存放了要锁定的行数据。 
     private int[] LockRow=new int[]{3,6,9,20}; 
     private void dataGrid_CurrentCellChanged(object sender, System.EventArgs e) { 
       //锁定表格行的算法 
       this.dataGrid.ReadOnly = false; 
       for(int i=0;i<LockRow.Length;i++){ 
         if(this.dataGrid.CurrentRowIndex==LockRow[i]){ 
           this.dataGrid.ReadOnly = true; 
           break; 
         } 
       } 
     }