# Efficiently Adding Column to DataGrid **Category:** [Epicor ERP 10](https://www.epiusers.help/c/e10/5) **Created:** 2016-11-15 13:32 UTC **Views:** 29345 **Replies:** 35 **URL:** https://www.epiusers.help/t/efficiently-adding-column-to-datagrid/36283 --- ## Post #1 by @tkoch What is the most efficient way to add a new column to a datagrid? In the past I have added the column and then on the InitializeRow event used the BOReader to retrieve the data, obviously if the grid has a lot of rows this slows down the application significantly. I don't know if there is a better method for doing this or if anyone has suggestions. Thanks, Ted --- ## Post #2 by @josecgomez Your best and most efficient way is a BAQ view. Write a BAQ that shows the data you need and then publish subscribe the BAQ view and bind the grid to it. If you tell me which screen / grid I may be able to provide a better example --- ## Post #3 by @tkoch Hi Jose, I have added a custom (date) field to the PO Release tab, that purchasing would like to see in the Buyer Workbench under PO's -> Open PO's -> Late, Today, This Week, Future. I have done something similar for the Part Transaction History Tracker in the past, but that form displays one part number at a time. This workbench is for multiple PO's, not sure how a BAQView would handle that to populate multiple rows. --- ## Post #4 by @josecgomez Well if there is no Part to Pivot off or anything like that you can just have the BAQ View stand on its own. I think it just tied to the "current" buyer? Either way you can just have a BAQ view driven off the current buyer and replace it with a BAQ View which has your custom field in it. --- ## Post #5 by @josecgomez Here's a quick example that does what you want ( and a brief video explaining how it works if ya wanna know) https://youtu.be/FYLPgCbQSDc ```cs //Using using Ice.Lib.Broadcast; //Class Level BAQDataView baqViewLate; public void CreateLateBAQView() { baqViewLate = new BAQDataView("LateOpenPos"); oTrans.Add("LateOpenPOBAQ",baqViewLate); string pubBinding = "POTotal.BuyerID"; IPublisher pub = oTrans.GetPublisher(pubBinding); if(pub==null) { oTrans.PublishColumnChange(pubBinding, "MyCustomPublish"); pub = oTrans.GetPublisher(pubBinding); } if(pub !=null) baqViewLate.SubscribeToPublisher(pub.PublishName, "POHeader_BuyerID"); } ``` --- ## Post #6 by @tkoch Thank you Jose. I will give this a go. --- ## Post #7 by @tkoch Jose, Can you share the BAQ you used for this? I'm guessing the criteria you used was PromiseDate < Today? --- ## Post #8 by @josecgomez I don't have it anymore it was an education DB so I replaced it, but yeah it was just PromiseDate < Today and then for adding 30 etc you can use the Date + X function in the BAQ --- ## Post #9 by @tkoch I got this working. Also, the PO Entry button on the form was not working because it is looking for a different EpiDataView. I added a new button with this code to get it to work. The only this that doesn't work is when the refresh button is clicked on the form the grid doesn't refresh the data. Anyone know how to refresh a BAQDataView? I've tried Notify and OnSearch methods, but didn't work. string view = mainDock.poDock1.openPOsPanel1.openPODock1.EpiSelectedSheet; string epiBinding = ""; if (view == null) { view = "poLate"; } int num = 0; if (view == "poLate") { epiBinding = "POLate.PONum"; if (baqViewLate.dataView.Count > 0) { num = int.Parse(baqViewLate.dataView[baqViewLate.Row]["PORel_PONum"].ToString()); } } else if (view == "poToday") { epiBinding = "POToday.PONum"; if (baqViewToday.dataView.Count > 0) { num = int.Parse(baqViewToday.dataView[baqViewToday.Row]["PORel_PONum"].ToString()); } } else if (view == "poThisWeek") { epiBinding = "POThisWeek.PONum"; if (baqViewThisWeek.dataView.Count > 0) { num = int.Parse(baqViewThisWeek.dataView[baqViewThisWeek.Row]["PORel_PONum"].ToString()); } } else if (view == "poFuture") { epiBinding = "POFuture.PONum"; if (baqViewFuture.dataView.Count > 0) { num = int.Parse(baqViewFuture.dataView[baqViewFuture.Row]["PORel_PONum"].ToString()); } } if (num != 0) { LaunchFormOptions launchObject = new LaunchFormOptions { PublisherKey = oTrans.GetPublisher(epiBinding).PublishKey, ValueIn = num }; ProcessCaller.LaunchForm(oTrans, "PMGO2001", launchObject); } else { ProcessCaller.LaunchForm(oTrans, "PMGO2001"); } --- ## Post #10 by @MukeshDesai I had successfully implemented your codes? Thanks for sharing best article. I was trying to extends this process in C# with more than one publisher and subscriber. We may publish more than one publisher and subscribe them in dashboard building. How can we pass more than one publisher using ? string pubBinding = "POTotal.BuyerID"; IPublisher pub = oTrans.GetPublisher(pubBinding); How can we consume this published values like your code? baqViewLate.SubscribeToPublisher(pub.PublishName, "POHeader_BuyerID"); Appreciated your support. Thanks, Mukesh Desai --- ## Post #11 by @tkoch I'm not 100% sure, but you can probably call SubscribeToPublisher multiple times to subscribe to multiple publishers. You would have to try that. --- ## Post #12 by @T11 @josecgomez That is a great explanation, thanks! --- ## Post #13 by @rnewell [quote="MukeshDesai, post:10, topic:36283"] Mukesh [/quote] Mukesh, were you ever able to make this work using more then one publish and subscribe value? We are trying to replace a grid in quote entry at the material line level and need to filter the Quote Number, Line Number and assembly number but have not been able to make it work Regards, --- ## Post #14 by @josecgomez Do do more than one publish subscribe just add additional publish and subscribe columns The same thing I do just add additional Publishers and additinoal Subscribe to publisher commands. --- ## Post #15 by @MukeshDesai I haven't got opportunity for testing. But reading from form and per Jose suggestion, its possible. --- ## Post #16 by @JoeBioTek This was very helpful! Thanks, Jose. We have a few versions of our CustomerEntryForm. I replaced an embedded dashboard with this on the first version and it worked as expected every time. I'm now apply the fix to our other customer entry screens and have run into a problem. I am using Customer.CustNum as the publisher. The first customer retrieved doesn't filter the BAQ as expected. Not when I type a customer ID and tab, nor when I use the button to search. The next customer and customers after that filter the BAQ as expected. What could I be doing prevent this from working on the first retrieve? --- ## Post #17 by @josecgomez Can you add CustID to your BAQ and filter on that? I wonder if the CustNum doesn't get populated right away? --- ## Post #18 by @JoeBioTek Great idea. I did try, but no luck. I did stumble across the reason though. I had version 1 of the CustomerEntryForm open so I could copy code from it. I use shift-click all the time to open a second instance of the same screen. In this case I did that and opened version 2 to paste into. I then shift-clicked to open version 2 in run-time mode and saw the problems. If I only have one instance of the screen open (not even the customization tools open) the code runs as I expect. The converted customization was a static class, so I am using a static BAQDataView member and static method to set it up. Since I am copying and pasting the same names, is it the fact that they are static that is causing the issue? --- ## Post #19 by @josecgomez Yeah potentially.... --- ## Post #20 by @John_Mitchell What would the syntax be for a >= date? For example, in Part Tran History Tracker there is a Starting Date and Cutoff Date, I have them both published but it only shows transactions where the date's are equal. Thanks, --- ## Post #21 by @Hally Used this today on the TFOrder Receipt form......Thanks a lot Jose. --- ## Post #22 by @asmar John - did you figure out the syntax for the >= date for published column? --- ## Post #23 by @John_Mitchell I never could, I ended up just building a dashboard using a smaller set of fields and a lot of parameters hard-coded since they didn't apply in our environment. Good Luck! --- ## Post #24 by @MjtBiz You can count me as another community member grateful to Jose for posting this! --- ## Post #25 by @adamk @josecgomez would you happen to have an example of subscribing to multiple fields? every time I try to add another field (I actually want to publish and subscribe to 3 fields from the BAQ) I get a error when loading the custom (even though the code compiles correctly every time) --- ## Post #26 by @josecgomez I don't have any code handy but you just do the subscribe again. Same code ``` //Once string pubBinding = "POTotal.BuyerID"; IPublisher pub = oTrans.GetPublisher(pubBinding); if(pub==null) { oTrans.PublishColumnChange(pubBinding, "MyCustomPublish"); pub = oTrans.GetPublisher(pubBinding); } if(pub !=null) baqViewLate.SubscribeToPublisher(pub.PublishName, "POHeader_BuyerID"); } ``` ``` //again but change the field string pubBinding2 = "POTotal.BuyerIDOtherField"; IPublisher pub2 = oTrans.GetPublisher(pubBinding2); if(pub2==null) { oTrans.PublishColumnChange(pubBinding2, "MyCustomPublish2"); pub2 = oTrans.GetPublisher(pubBinding2); } if(pub2 !=null) baqViewLate.SubscribeToPublisher(pub2.PublishName, "POHeader_BuyerIDOtherField"); } ``` --- ## Post #27 by @adamk Ok thanks @josecgomez - That was how I did it (was getting a load error as I forgot to change the 2nd published field, so it was trying to do it twice), but as soon as I add that second field to subscribe to, my grid goes blank and returns nothing....with 1 field it works, but with 2 it gives me nothing...strange...I'll keep trying Thanks! --- ## Post #28 by @Chris_Conn By chance are the pub/sub fields the same key in both views? I had issues when I tried to sync a UDx and UDxA on the same key name (ie. pub table 1 = UDx.Key sub table 2 = UDx.Key). I ended up using SetParentView i think to get around it. --- ## Post #29 by @knash post your function. might help to have another set of eyes on the code. --- ## Post #30 by @surendrapal @josecgomez can we pass static param to baq with this? --- ## Post #31 by @adamk Hey @Chris_Conn, they are not looking at the same field. When I publish just the PartNum field, it works, and my grid shows ALL of the parts with that criteria. I want to add JobNum and ASM so that it only brings back the record that I am looking for but as soon as I add the second (haven't even tried to do three yet) the grid just goes blank. As @knash suggested I will post what I have and hopefully be able to tell me where I am going wrong! --- ## Post #32 by @knash Here is what I used in the past to make this works. public void CreateLateBAQView() { JobTrackerViewLate = new BAQDataView("ETK_JobTrackerMatNoPar"); oTrans.Add("LateOpenJobMatBAQ",JobTrackerViewLate); string pubBinding = "JobHead.JobNum"; IPublisher pub = oTrans.GetPublisher(pubBinding); if(pub==null) { oTrans.PublishColumnChange(pubBinding, "MyCustomPublish"); pub = oTrans.GetPublisher(pubBinding); } if(pub !=null) JobTrackerViewLate.SubscribeToPublisher(pub.PublishName, "JobMtl_JobNum"); pubBinding = "CurrAsm.AssemblySeq"; IPublisher pub2 = oTrans.GetPublisher(pubBinding); if(pub2==null) { oTrans.PublishColumnChange(pubBinding, "MyCustomPublish2"); pub2 = oTrans.GetPublisher(pubBinding); } if(pub2 !=null) JobTrackerViewLate.SubscribeToPublisher(pub2.PublishName, "JobMtl_AssemblySeq"); } --- ## Post #33 by @adamk I think @surendrapal has me on the right path (was nice enough to skype me and walk me through a few things) - Will update shortly! As always, very much appreciate everyone's time!! --- ## Post #34 by @Shizar115 Hi @josecgomez and @tkoch , I am trying to replace the gridview in Method Tracker's Material->List section. This is my code: ``` // ************************************************** // Custom code for BOMTrackerForm // Created: 2021-11-18 6:20:47 PM // ************************************************** extern alias Erp_Contracts_BO_EngWorkBench; extern alias Erp_Contracts_BO_ECORevSearch; extern alias Erp_Contracts_BO_BomSearch; extern alias Erp_Contracts_BO_Part; extern alias Erp_Contracts_BO_PartRevSearch; extern alias Erp_Contracts_BO_Customer; using System; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Windows.Forms; using Erp.Adapters; using Erp.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; 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 baqViewMT; 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 CreatMTtable(); } public void CreatMTtable() { baqViewMT = new BAQDataView("ACSL_MethodTracker"); oTrans.Add("ACSL_MethodTrackerBAQ",baqViewMT); string pubBinding1 = "PartRev.RevisionNum"; string pubBinding2 = "PartMtl.MtlSeq"; IPublisher pub1 = oTrans.GetPublisher(pubBinding1); IPublisher pub2 = oTrans.GetPublisher(pubBinding2); if(pub1==null) { oTrans.PublishColumnChange(pubBinding1, "MyCustomPublish1"); pub1 = oTrans.GetPublisher(pubBinding1); } if(pub1!=null) { baqViewMT.SubscribeToPublisher(pub1.PublishName,"PartRev_PartNum"); } if(pub2==null) { oTrans.PublishColumnChange(pubBinding2, "MyCustomPublish2"); pub2 = oTrans.GetPublisher(pubBinding2); } if(pub2!=null) { baqViewMT.SubscribeToPublisher(pub2.PublishName,"PartMtl_MtlSeq"); } } 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 // End Custom Code Disposal } } ``` Compilation is successful: ![image|690x445](upload://7FUsK5cpPRXhhohs7JKXhMdNWdA.png) I get this error when I load the form: ![image|659x443](upload://xqPOOng23av7e4LTP4p4OMVFvTo.png) Would you be able to advise? Many thanks in advance --- ## Post #35 by @jgiese.wci Looks like whatever it is you're replacing you're breaking native dependent code. Are you binding your new view to the original grid? If so that could be the issue. --- ## Post #36 by @knash Have you been able to get this to work. Looks like you have column that isn't correct. string pubBinding1 = "PartRev.RevisionNum"; baqViewMT.SubscribeToPublisher(pub1.PublishName,"PartRev_PartNum"); PartNum?? for both or RevisionNum. ``` string pubBinding1 = "PartRev.RevisionNum"; string pubBinding2 = "PartMtl.MtlSeq"; IPublisher pub1 = oTrans.GetPublisher(pubBinding1); IPublisher pub2 = oTrans.GetPublisher(pubBinding2); if(pub1==null) { oTrans.PublishColumnChange(pubBinding1, "MyCustomPublish1"); pub1 = oTrans.GetPublisher(pubBinding1); } if(pub1!=null) { baqViewMT.SubscribeToPublisher(pub1.PublishName,"PartRev_PartNum"); } ``` --- **Canonical:** https://www.epiusers.help/t/efficiently-adding-column-to-datagrid/36283 **Original content:** https://www.epiusers.help/t/efficiently-adding-column-to-datagrid/36283