VB Reflection Code

Thanks to the excellent help of @hkeric.wci and @LoganS I have been able to use reflection to knock a few things off my users wish list (thanks so much!) Looking for some code guidance for reflection on a VB customization that I am trying to limp along with until I can upgrade to Kinetic and have it re-written next year. I have a button that clears a custom grid and fields but it leaves the info on the base form and treeview. The only way to eliminate it is using the clear button in the menu bar. I would like to keep the logic to the custom button to clear the grid and then add the logic to mimic the clear tool. Going through older posts here I have started with:

Dim mi as System.Reflection.MethodInfo

mi = GetType(Erp.UI.App.InvTransferEntry.InvTransferForm).GetMethod("Clear", BindingFlags.NonPublic Or BindingFlags.Instance)

mi.Invoke(InvTransferForm, new object() {})

Which compiles but when I press the button the grid clears and I receive an error

Application Error
Exception caught in: App.InvTransferEntry.InvTransferForm.EP.BMF.Customization.AJCDrumWash.CustomCode.14

Error Detail

Message: Object reference not set to an instance of an object.
Program: App.InvTransferEntry.InvTransferForm.EP.BMF.Customization.AJCDrumWash.CustomCode.14.dll
Method: btnDrumClear_Click

Client Stack Trace

at Script.btnDrumClear_Click(Object sender, EventArgs args)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButtonBase.OnClick(EventArgs e)
at Ice.Lib.Framework.EpiButton.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseEventArgs e)
at Ice.Lib.Framework.EpiButton.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

In your button that calls the custom grid, do the same reflection as the “SaveTools”, but instead call “ClearTools”. The underlying BO never gets cleared, that’s why it stays in the tree. Clearing a grid is cosmetic/UI only. The data is still loaded underneath it. You could also bring in the BO, and clear the reference but if you’re just trying to mimic the clear button you can call the reflection version where needed.