Clear UltraGrid

Hi folks, I have added a BAQ Dataview and bound it to an UltraGrid. This is working great, based on instructions found here from Jose Gomez. The issue I am having is that when I clear the form (click the sweep or eraser icon on the tool bar), the UltraGrid doesn’t clear. The BAQ Dataview results remain in the grid. The grid does update when I select a new record for the main form. This form is using UD105. I’d like to have the grid clear when the form clears to avoid confusing the users. Running 10.2.300.15

You’ll want to write a method off of the Clear toolbar click event that also clears the data grid.
I’m not 100% sure of the tool name, but you could find that out easily enough. This is what the code would look like

private void baseToolbarsManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
{
    if (args.Tool.Key == "ClearTool")
    {
      //clear your ultragrid here
    }
}

Thanks Aaron, in your code sample you have

//clear your ultragrid here

I am unsure what I would put in that section.

I think there is a ultraGridName.Clear() method, hold on let me check

No Clear() method, darn. Are you filling the data table behind the ultragrid? If you clear the contents of the data table, it will clear the ultragrid. If you show some code I can help with that too

Aaron, thanks again for the help. I am using a BAQview to fill the grid. That portion is working. Here’s my code:

BAQDataView baqViewPartBin;
 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

 	// End Wizard Added Custom Method Calls
 	CreatePartBinBAQView();
 }
 public void CreatePartBinBAQView()
 {
 baqViewPartBin = new BAQDataView("PartPrimBin2");
 	oTrans.Add("PartPrimBinBAQ",baqViewPartBin);

 	string pubBinding = "UD105.Key1";
 	IPublisher pub = oTrans.GetPublisher(pubBinding);
 	if(pub==null)
 	{
 		oTrans.PublishColumnChange(pubBinding,"MyCustomPublish");
 		pub = oTrans.GetPublisher(pubBinding);
 	}

 	if(pub !=null)
 		baqViewPartBin.SubscribeToPublisher(pub.PublishName,"PlantWhse_PartNum");
 }

I am so close on this. I can get the grids to clear, but it seems to leave the form in a weird state where typing a new value and hitting tab doesn’t display data until I click on a different tab then click back on the original tab. I am also struggling with refreshing the BAQDataView. I’ve seen a post from Jose on refreshing the dataview, but can’t seem to make it work for me.

{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
	BAQDataView baqViewPartBin;
	BAQDataView baqViewPiecePart;
	BAQDataView baqViewPartInv;
	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.UD105Form.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.UD105Form_AfterToolClick);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
		CreatePartBinBAQView();
		CreatePiecePartView();
		CreateInvPartView();
	}
	public void CreatePartBinBAQView()
	{
	baqViewPartBin = new BAQDataView("PartPrimBin2");
		oTrans.Add("PartPrimBinBAQ",baqViewPartBin);

		string pubBinding = "UD105.Key1";
		IPublisher pub = oTrans.GetPublisher(pubBinding);
		if(pub==null)
		{
			oTrans.PublishColumnChange(pubBinding,"MyCustomPublish");
			pub = oTrans.GetPublisher(pubBinding);
		}

		if(pub !=null)
			baqViewPartBin.SubscribeToPublisher(pub.PublishName,"PlantWhse_PartNum");
	}
public void CreatePiecePartView()
	{
	baqViewPiecePart = new BAQDataView("PieceParts");
		oTrans.Add("PiecePartBAQ",baqViewPiecePart);

		string pubBinding = "UD105.Key1";
		IPublisher pub = oTrans.GetPublisher(pubBinding);
		if(pub==null)
		{
			oTrans.PublishColumnChange(pubBinding,"MyCustomPublish2");
			pub = oTrans.GetPublisher(pubBinding);
		}

		if(pub !=null)
			baqViewPiecePart.SubscribeToPublisher(pub.PublishName,"UD105_Key1");
	}
public void CreateInvPartView()
	{
	baqViewPartInv = new BAQDataView("PartInventory");
		oTrans.Add("PartInvBAQ",baqViewPartInv);

		string pubBinding = "UD105.Key1";
		IPublisher pub = oTrans.GetPublisher(pubBinding);
		if(pub==null)
		{
			oTrans.PublishColumnChange(pubBinding,"MyCustomPublish3");
			pub = oTrans.GetPublisher(pubBinding);
		}

		if(pub !=null)
			baqViewPartInv.SubscribeToPublisher(pub.PublishName,"PartBin_PartNum");
	}

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

		this.UD105Form.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.UD105Form_AfterToolClick);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal
		this.baqViewPartBin = null;
		// End Custom Code Disposal
	}

	private void UD105Form_AfterToolClick(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
	{
	if (args.Tool.ToString() == "[ClearTool] - ButtonTool") {
	epiUltraGridC1.DataSource = null;
	//epiUltraGridC1.ResetDisplayLayout();
	epiUltraGridC1.Layouts.Clear();
	epiUltraGridC2.DataSource = null;
	//epiUltraGridC2.ResetDisplayLayout();
	epiUltraGridC2.Layouts.Clear();
	epiUltraGridC3.DataSource = null;
	//epiUltraGridC3.ResetDisplayLayout();
	epiUltraGridC3.Layouts.Clear();
	//MessageBox.Show("Cleared!");
	}
if (args.Tool.ToString() == "[RefreshTool] - ButtonTool") {
	
	MessageBox.Show("REFRESH!");

	}
	}

}
// BAQ Clear Method
private void ClearBAQDataView(BAQDataView iBaqView)
{
    FieldInfo dqAdapter = iBaqView.GetType().GetField("dqAdapter", BindingFlags.Instance | BindingFlags.NonPublic);
    Ice.Adapters.DynamicQueryAdapter dsQ = (Ice.Adapters.DynamicQueryAdapter)dqAdapter.GetValue(iBaqView);
    dsQ.QueryResults.Clear();
}

// Handle clicking events of da toolz
private void CapabilityForm_AfterToolClick(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
{
    switch(args.Tool.Key)
    {
        case "NewMenuTool":
            if(oTrans.LastView == bdvPartsList)
            {
                if(edvCapResLnk.Row > -1)
                {
                    GetNewMachinePart();
                }
            }
            break;
        case "ClearTool":
            ClearBAQDataView(bdvPartsList);
            break;     
        case "UndoTool":
            RefreshBAQDataView(bdvPartsList);
            break;;     
        case "RefreshTool":
            RefreshBAQDataView(bdvPartsList);
            break;
        case "SaveTool":
            UpdateBAQDataView(bdvPartsList);
            RefreshBAQDataView(bdvPartsList);
            break;
        case "DeleteTool":
            if(oTrans.LastView == bdvPartsList)
            {
                DeleteMachinePart();
            }
            break;
    }
}
1 Like

HI,

Why using reflection to clear the BAQDataView? Isn’t iBaqView.dataView.Table.Clear() enough?

Because I can’t find any documentation on how to properly do this, and this is pieced together from what I am able to find in the forums. What would be the proper way to use what you suggest?

Joshua, the clear seems to work great! Thank you! Do you have the method for the refresh? I didn’t see it in the code you pasted.

I try to use the adapters as much as possible. Epicor puts their own spin on just about everything they touch so I don’t like to risk missing anything they might have between them and native C# functions.

2 Likes

All of this are parts and pieces from base code I use for using a UBAQ DataView as a child table in a screen (think child table wizard in customization mode) This is about a quarter of the code but it’s oh so sweet.

// BAQ Execute (GetList) Method
private void RefreshBAQDataView(BAQDataView iBaqView)
{
    MethodInfo mi = iBaqView.GetType().GetMethod("invokeExecute", BindingFlags.Instance | BindingFlags.NonPublic);
    mi.Invoke(iBaqView, new object[]{ true });
}

// BAQ RunCustomAction Method (Required for Delete since BAQs don't have a delete record method)
private void RunCustomActionBAQDataView(BAQDataView iBaqView, string iAction)
{
    Assembly assembly = Assembly.LoadFrom("Ice.Lib.EpiClientLib.dll");
    Type t = assembly.GetType("Ice.Lib.Framework.BAQUpdater");
    MethodInfo mi = t.GetMethod("BAQRunCustomAction", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
    mi.Invoke("Ice.Lib.Framework.BAQUpdater", new object[]{iBaqView, iAction});
}
 
// BAQ FieldUpdate Method
private void FieldUpdateBAQDataView(BAQDataView iBaqView, string iColumn, DataRow iSrcRow)
{
    Assembly assembly = Assembly.LoadFrom("Ice.Lib.EpiClientLib.dll");
    Type t = assembly.GetType("Ice.Lib.Framework.BAQUpdater");
    MethodInfo mi = t.GetMethod("BAQFieldUpdate", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
    mi.Invoke("Ice.Lib.Framework.BAQUpdater", new object[]{iBaqView, iColumn, iSrcRow});
}
 
// BAQ FieldValidate Method
private bool FieldValidateBAQDataView(BAQDataView iBaqView, string iColumn, DataRow iSrcRow, object iProposed)
{
    Assembly assembly = Assembly.LoadFrom("Ice.Lib.EpiClientLib.dll");
    Type t = assembly.GetType("Ice.Lib.Framework.BAQUpdater");
    MethodInfo mi = t.GetMethod("BAQFieldUpdate", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
    return (bool)mi.Invoke("Ice.Lib.Framework.BAQUpdater", new object[]{iBaqView, iColumn, iSrcRow, iProposed});
}
 
// Used for additional BAQ filtering
private void FilterBAQDataView(BAQDataView iBaqView, string iWhereClause)
{
    iBaqView.AdditionalFilter = iWhereClause;
    iBaqView.dataView.RowFilter = iWhereClause;
    iBaqView.Notify(new EpiNotifyArgs(oTrans, 0, EpiTransaction.NotifyType.Initialize));
}
 
// Need to merge the dataset back from update all rows must have RowIdent and SysRowID!
private void MergeResults(DataTable og, DataTable res)
{
    foreach(DataRow dr in res.Rows)
    {
        var drs = og.Select(string.Format("SysRowID ='{0}'", dr["SysRowID"]));
        if(drs != null && drs.Length>0)
        {
            drs[0].ItemArray = dr.ItemArray;
        }
        else
        {
            var drNew = og.NewRow();
            drNew.ItemArray = dr.ItemArray;
        } 
    }
}
3 Likes

Joshua, YOU ARE THE MAN! Thank you very much!.

I must still have something wrong though. The clear does clear the data from the UltraGrids, and refresh does seem to refresh the data. But if I enter a new value, I still have to click on another tab and then back on the original tab to see the data change.

// Custom code for UD105Form
// Created: 5/2/2017 7:29:40 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Ice.Lib.Broadcast;
using System.Reflection;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
	BAQDataView baqViewPartBin;
	BAQDataView baqViewPiecePart;
	BAQDataView baqViewPartInv;
	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.UD105Form.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.UD105Form_AfterToolClick);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
		CreatePartBinBAQView();
		CreatePiecePartView();
		CreateInvPartView();
	}
	public void CreatePartBinBAQView()
	{
	baqViewPartBin = new BAQDataView("PartPrimBin2");
		oTrans.Add("PartPrimBinBAQ",baqViewPartBin);

		string pubBinding = "UD105.Key1";
		IPublisher pub = oTrans.GetPublisher(pubBinding);
		if(pub==null)
		{
			oTrans.PublishColumnChange(pubBinding,"MyCustomPublish");
			pub = oTrans.GetPublisher(pubBinding);
		}

		if(pub !=null)
			baqViewPartBin.SubscribeToPublisher(pub.PublishName,"PlantWhse_PartNum");
	}
public void CreatePiecePartView()
	{
	baqViewPiecePart = new BAQDataView("PieceParts");
		oTrans.Add("PiecePartBAQ",baqViewPiecePart);

		string pubBinding = "UD105.Key1";
		IPublisher pub = oTrans.GetPublisher(pubBinding);
		if(pub==null)
		{
			oTrans.PublishColumnChange(pubBinding,"MyCustomPublish2");
			pub = oTrans.GetPublisher(pubBinding);
		}

		if(pub !=null)
			baqViewPiecePart.SubscribeToPublisher(pub.PublishName,"UD105_Key1");
	}
public void CreateInvPartView()
	{
	baqViewPartInv = new BAQDataView("PartInventory");
		oTrans.Add("PartInvBAQ",baqViewPartInv);

		string pubBinding = "UD105.Key1";
		IPublisher pub = oTrans.GetPublisher(pubBinding);
		if(pub==null)
		{
			oTrans.PublishColumnChange(pubBinding,"MyCustomPublish3");
			pub = oTrans.GetPublisher(pubBinding);
		}

		if(pub !=null)
			baqViewPartInv.SubscribeToPublisher(pub.PublishName,"PartBin_PartNum");
	}

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

		this.UD105Form.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.UD105Form_AfterToolClick);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal
		
		// End Custom Code Disposal
	}

	private void RefreshBAQDataView(BAQDataView iBaqView)
	{
    	MethodInfo mi = iBaqView.GetType().GetMethod("invokeExecute", BindingFlags.Instance | BindingFlags.NonPublic);
    	mi.Invoke(iBaqView, new object[]{ true });
	}
	private void ClearBAQDataView(BAQDataView iBaqView)
	{
    	FieldInfo dqAdapter = iBaqView.GetType().GetField("dqAdapter", BindingFlags.Instance | BindingFlags.NonPublic);
    	Ice.Adapters.DynamicQueryAdapter dsQ = (Ice.Adapters.DynamicQueryAdapter)dqAdapter.GetValue(iBaqView);
    	dsQ.QueryResults.Clear();
	}
	private void UD105Form_AfterToolClick(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
	{
		if (args.Tool.ToString() == "[ClearTool] - ButtonTool") {
		ClearBAQDataView(baqViewPartBin);
		ClearBAQDataView(baqViewPiecePart);
		ClearBAQDataView(baqViewPartInv);
		//MessageBox.Show("CLEAR!");	
		}

		if (args.Tool.ToString() == "[RefreshTool] - ButtonTool") {
		RefreshBAQDataView(baqViewPartBin);
		RefreshBAQDataView(baqViewPiecePart);
		RefreshBAQDataView(baqViewPartInv);
		//MessageBox.Show("REFRESH!");

		}
	}

}

Looks like the wierd behavior after clearing the form is not being caused by any of this code. I am working with a UD form (UD105) and it appears to be a tab order issue. If I pull the base form up, it works as expected. But as soon as I hide or change tab order I get the weird behavior.

Is the issue relating to the key fields and loading data into the screen?

I think so. Like I said, if I use the base form, it works. But if I hide the fields I’m not using, this seems to break tab order and the ability to enter a value and hit tab to have the record come up. I ended up assigning a hot key to do the search, and I think that’s going to work OK for the users.

so the UD forms rely on all 5 fields. There is logic that is supposed to ignore them based on if they are visible or not, but his can sometimes cause erratic behaviour. In some cases I’ve rebuilt the OnKeyFieldValidation method from scratch and ensured that the form behaves as I like to call it NAF or (Native As Flip (expletive))

I wonder if my issue is messing with the tab order as well as turning off visibility. I will test that out.

just for kicks keep all fields showing for now just to test that theory.

The base logic that can cause some erratic behaviour