2015-09-08 99 views
1

我想在特定條件(標誌)上使某些單元格只讀。但我有問題來設置確切的條件。我有一個非空位列,並試圖設置其值的條件。 這裏是我的代碼:在ultragrid中獲取特定單元格值的條件

private void grdOtherItemsInfo_InitializeLayout(object sender, InitializeLayoutEventArgs e) 
    { 
     UltraGridBand band; 
     try 
     { 
      band = e.Layout.Bands[0]; 

      band.ColHeaderLines = 2; 
      foreach (UltraGridRow row in **can't find right option**) 
      { 
       if (row.Cells[OtherItemStoreRequisitionForBatchChild.IsAutoDispense].Value.ToString() == "1") 
       { 
        band.Columns[OtherItemStoreRequisitionForBatchChild.IsAutoDispense].CellActivation = Activation.ActivateOnly; 
        band.Columns[OtherItemStoreRequisitionForBatchChild.IndentedUOM].CellActivation = Activation.ActivateOnly; 
        band.Columns[OtherItemStoreRequisitionForBatchChild.IndentedQty].CellActivation = Activation.ActivateOnly; 
       } 
      } 
    } 
+0

grdOtherItemsInfo.Rows? – Steve

+0

@Steve grdOtherItemsInfo.Rows沒有工作,因爲有超過1個e.layout.bands索引,我沒有在這裏提到。無論如何非常感謝。我得到了一個解決方案,我添加了一個答案。 – Mimi

回答

2
foreach (UltraGridRow row in grdOtherItemsInfo.Rows) 
     { 
      foreach (UltraGridRow urow in grdChemicalItemInfo.Rows[row.Index].ChildBands[0].Rows) 
      { 
       if (Convert.ToBoolean(urow.Cells[OtherItemStoreRequisitionForBatchChild.IsAutoDispense].Value)) 
       { 
        foreach (UltraGridCell col in urow.Cells) 
        { 
         col.Activation = Activation.ActivateOnly; 
        } 
       } 
      } 
     } 
1

樂隊已經沒有行屬性。如果您需要遍歷所有行,則需要調用grdOtherItemsInfo.Rows。您可以使用這樣的代碼:

private void grdOtherItemsInfo_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) 
{ 
    UltraGridBand band; 
    try 
    { 
     band = e.Layout.Bands[0]; 

     band.ColHeaderLines = 2; 

     // Rows collection of the grid contains the rows in Band[0] or the top level of GroupByRows 
     foreach (UltraGridRow row in this.grdOtherItemsInfo.Rows) 
     { 
      // Check if the row is DataRow, otherwise you will get an exception when you call Cell property of not data row 
      if (row.IsDataRow) 
      { 
       // Cashing the cell so not taking it twice 
       UltraGridCell cell = row.Cells[OtherItemStoreRequisitionForBatchChild.IsAutoDispense]; 
       if (cell.Value.ToString() == "1") 
       { 
        // Setting the cells' Activation will set each cell its own activation 
        // If you set it to the column all the cells in the column will have same activation 
        cell.Activation = Activation.ActivateOnly; 
        row.Cells[OtherItemStoreRequisitionForBatchChild.IndentedUOM].Activation = Activation.ActivateOnly; 
        row.Cells[OtherItemStoreRequisitionForBatchChild.IndentedQty].Activation = Activation.ActivateOnly; 
       } 
      } 
     } 
    } 
    catch(Exception ex) 
    { 
     // TODO: ... 
    } 
} 

注意,在你的代碼你通過所有的行,並要設置取決於一些列的單元格值的列CellActivation。在這種情況下,CellActivation可能會改變幾次,但最終它將取決於最後一行中單元格的值。在列上設置CellActivation可強制該列中的所有單元具有相同的CellActivatio。如果您需要爲列中的每個單元格設置不同的CellActivation,則需要設置每個單元格的激活屬性 - 這就是我發送的代碼所做的。

檢查也this鏈接展示如何遍歷網格行

+0

非常感謝。我昨天已經做到了。由於我在這裏沒有提到超過1個e.layout.bands索引,所以我遇到了問題。所以grdOtherItemsInfo.Rows不起作用。我得到了一個解決方案,我添加了一個答案。 – Mimi

相關問題