2012-05-17 40 views
0

在我的syncfusion網格中,必須根據類型使某些系列單元格不可編輯。 如果類型是'XXX',那麼單元格是可編輯的,如果類型是'YYY','ZZZ'則單元格是不可編輯的使網格中的單元格不可編輯

所以這裏;我做了什麼。

private void theGrid_CurrentCellChanging(object sender, System.ComponentModel.CancelEventArgs e) 
    { 
     fp_data_typ typ; 
     int nSeries = theData.GetNumSeries(); 
     for (int i = 0; i < nSeries; i++) 
     { 
      typ = theData.CheckType(i); 
      if (!(typ == 'XXX')) 
      { 

       e.Cancel = true; 
      } 
     } 

    } 

我不知道我是否應該使用theGrid_CurrentCellChanging事件或theGrid_CurrentCellStartEditing。文檔不是很清楚。爲我提供了大量的事件來處理單元格編輯。

代碼早期的工作方式不正確。如果網格包含可編輯和不可編輯系列的組合,則不起作用。我:如果它同時具有xxx)可編輯和'yyy'(不可編輯),則它們都是不可編輯的。

回答

0

我能夠獲得當前單元格的列索引,並從那裏將e.cancel設置爲true/false。我沒有爲整個網格設置e.cancel,而是去編輯單元格。

0

以下活動將幫助您達到您的要求。

//Use this if you want to control the ReadOnly setting while loading itself 
grid.QueryCellInfo += new GridQueryCellInfoEventHandler(grid_QueryCellInfo); 

void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
{ 
    if (e.Style.CellValue.Equals("YYY")) 
    { 
     e.Style.ReadOnly = true; 
    } 
} 

//Use this if you want to Validate while Editing 
grid.CurrentCellValidating += new CurrentCellValidatingEventHandler(grid_CurrentCellValidating); 

void grid_CurrentCellValidating(object sender, CurrentCellValidatingEventArgs e) 
{ 
    //Will deactive the cell and new value will be discarded 
    //e.NewValue = e.OldValue; 

    //To remain in Edit mode without committing the vlaue 
    e.Cancel = true; 
} 

感謝, 西瓦庫瑪

相關問題