DataGrid通过程序的方式锁定任意指定的行

就写在 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;
        }

      }

    }
原文地址:https://www.cnblogs.com/Chinasf/p/139206.html