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

本文关键字:单元 条件 网格 | 更新日期: 2023-09-27 18:11:36

我试图在特定条件(标志)下使一些单元格只读。但我在设定确切的条件时遇到了问题。我有一个非空位列,并试图对其值设置条件。下面是我的代码:

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

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

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

带没有rows属性。如果需要遍历所有行,则需要调用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,则需要设置每个单独单元格的Activation属性-这就是我发送给您的代码所做的。

也检查这个链接,显示如何迭代网格的行