Filtering an Ultragrid

Andrew ClementsEpicor Coding, Epicor Developement

Hi,

I got asked the other day about filtering transactions from the ‘Get Request’ screen, so that only ‘STK-MTL’ transaction types are displayed.

You can do this by creating an ‘InitializeRow’ event handler.

The code snippet below explains how to do it

public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
//create a variable to hold the grid guid
EpiUltraGrid RequestGrid;

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls
//map variable to grid using GUID
RequestGrid = (EpiUltraGrid)csm.GetNativeControlReference("8fb7f568-4631-4284-a62f-e891d6d8002a");
//create event handler
RequestGrid.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(grdRequestLines_InitializeRow);

// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal

// End Wizard Added Object Disposal

// Begin Custom Code Disposal
//dispose of event handler
RequestGrid.InitializeRow -= new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(grdRequestLines_InitializeRow);

// End Custom Code Disposal
}

private void grdRequestLines_InitializeRow (object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
if (e.ReInitialize)
{
}
else
{
// write condition to stop anything other than STK-MTL to be displayed
if (e.Row.Cells["TranType"].Value.ToString() != "STK-MTL" )
{
e.Row.Hidden = true;

}
else
{

}

}
}
}

Alternatively, if you actually want to delete the row from the dataset

private void grdRequestLines_InitializeRow (object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
if (e.ReInitialize)
{
}
else
{

if (e.Row.Cells["TranType"].Value.ToString() != "STK-MTL" )
{
//delete all other transaction type rows
int index = e.Row.Index;
e.Row.Delete(false);
RequestGrid.Rows[index].Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.FireInitializeRow);

}
else
{

}

}