在超网格中获取特定单元格值的条件

时间:2015-09-08 08:54:29

标签: c# infragistics

我试图在特定条件下(标记)使一些单元格只读。但我确定准确的条件是有问题的。我有一个非空位列,并试图设置其值的条件。 这是我的代码:

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

1 个答案:

答案 0 :(得分: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链接