Add columns to existing grid & populate cells

I am adding a few columns to the Out-of-the-Box grids on PO Suggestions Entry form and populating cells with data from a BAQ. For some reason, populating the cells takes a painfully long time. 3min 20sec for ~450 rows.The BAQ executes on form load, no performance issue there. Data is stored in a List, then applied to custom cells in the grid’s InitializeRow event.

See code below. Is there a better way?


Initialize (Add grid columns)

public void InitializeCustomCode()
{
    drawingInfoQueryAdapter = new DynamicQueryAdapter(oTrans);
    drawingInfoQueryAdapter.BOConnect();

    // ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
    // Begin Wizard Added Variable Initialization

    this.MtlSug_Row.EpiRowChanged += new EpiRowChanged(this.MtlSug_AfterRowChange);
    this.SubSug_Row.EpiRowChanged += new EpiRowChanged(this.SubSug_AfterRowChange);

    // End Wizard Added Variable Initialization

    // End Wizard Added Custom Method Calls

    materialGrid = (Ice.Lib.Framework.EpiUltraGrid)csm.GetNativeControlReference("4d59326f-7a76-4c5c-8e2c-54e630db64da");
    SetupGrid(materialGrid);

    subcontractGrid = (Ice.Lib.Framework.EpiUltraGrid)csm.GetNativeControlReference("fcef0a0c-90f6-48b5-8133-f892a2515b84");
    SetupGrid(subcontractGrid);
}

/// Add PhaseID, DrawingInfo columns to specified grid.
private void SetupGrid(EpiUltraGrid grid)
{
    // Add columns
    grid.DisplayLayout.Bands[0].Columns.Add("PhaseID", "Section");
    grid.DisplayLayout.Bands[0].Columns.Add("DrawingInfo", "Drawing");

    // Get columns
    var colPhaseID = grid.DisplayLayout.Bands[0].Columns["PhaseID"];
    var colDrawingInfo = grid.DisplayLayout.Bands[0].Columns["DrawingInfo"];

    // Set Header Position
    colPhaseID.Header.VisiblePosition = 4;
    colDrawingInfo.Header.VisiblePosition = 5;

    // Set Cell Activation
    colPhaseID.CellActivation = Activation.ActivateOnly;
    colDrawingInfo.CellActivation = Activation.ActivateOnly;

    // Register InitializeRow event
    materialGrid.InitializeRow += new InitializeRowEventHandler(poSuggestionsGrid_InitializeRow);
}



Form Load (Get BAQ Results)

private void POSuggEntryForm_Load(object sender, EventArgs args)
{
    InitializeDrawingInfo();
}

private void InitializeDrawingInfo()
{
    var drawingInfoBaqID = "NewPOSugg_DrawingInfo";
    var queryExecutionDataSet = drawingInfoQueryAdapter.GetQueryExecutionParametersByID(drawingInfoBaqID);
    drawingInfoQueryAdapter.ExecuteByID(drawingInfoBaqID, queryExecutionDataSet);
    
    var drawingInfoTable = drawingInfoQueryAdapter.QueryResults.Tables["Results"];
    drawingInfoRows = drawingInfoTable.Rows.Cast<DataRow>().ToList();
}



InitializeRow (Update custom cells)

public void poSuggestionsGrid_InitializeRow(object sender,Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
    UpdateGridRow(e.Row);
}

private void UpdateGridRow(UltraGridRow row)
{
    var jobNum = row.Cells["JobNum"].Value.ToString();
    var partNum = row.Cells["PartNum"].Value.ToString();
    var revisionNum = row.Cells["RevisionNum"].Value.ToString();

    if(!string.IsNullOrEmpty(jobNum))
    {
        var drawingDetailsRow = drawingInfoRows.FirstOrDefault(drawingInfoRow =>    drawingInfoRow["JobMtl_JobNum"].ToString() == jobNum &&
                                                                                    drawingInfoRow["JobMtl_PartNum"].ToString() == partNum &&
                                                                                    drawingInfoRow["JobMtl_RevisionNum"].ToString() == revisionNum);

        if (drawingDetailsRow != null)
        {
            SetRowDrawingDetails(row, drawingDetailsRow);
        }
    }
}

private void SetRowDrawingDetails(UltraGridRow gridRow, DataRow drawingDetailsRow)
{
    var phaseID = drawingDetailsRow["JobHead_PhaseID"].ToString();
    var section = string.Empty;

    if(phaseID.Length >= 6)
    {
        section = phaseID.Substring(3, 3);
    }

    gridRow.Cells["PhaseID"].Value = section;

    var drawingNumber = drawingDetailsRow["JobMtl_MtlDrawingNumber_c"].ToString();
    var drawingRevision = drawingDetailsRow["JobMtl_MtlDrawingRevision_c"].ToString();
    var drawingInfoString = (!string.IsNullOrWhiteSpace(drawingNumber) ? drawingNumber : "-") +
                            (!string.IsNullOrWhiteSpace(drawingRevision) ? string.Format(" [{0}]", drawingRevision) : string.Empty);
    
    gridRow.Cells["DrawingInfo"].Value = drawingInfoString;
}

Check this out:

3 Likes

Hmmm thanks for pointing that one out @Chris_Conn. I have a mod on landed cost entry that might benefit from that.

1 Like

Worked a treat…well at least better. Not lightning fast, but the whole delete bulk lines on the container is supposed to be performed as an exception, rather than the norm.