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;
        }

      }

    }
posted @ 2005-04-17 13:15  suifei  阅读(1239)  评论(3编辑  收藏  举报