在Lookup界面添加选中复选框列并启用多选,求通用实现方法
Great question! When working with Acumatica lookups—like the Price Class selector on the AR209500 Discount screen—and needing to enable multi-select to add multiple records directly to a grid without complex filtering, there are a few streamlined, general-purpose approaches you can use:
LookupMultiSelect Control This is the most straightforward method, as it’s built specifically for multi-select lookup scenarios. Here’s how to implement it:
- DAC Setup: If you’re storing selected values, ensure your field can handle multiple entries (either use a string field for comma-separated IDs, or leverage a detail DAC like
DiscountDetailon AR209500 for individual records). - ASPX Modification: Replace the standard
PXLookupcontrol withPXLookupMultiSelect, and configure it to tie directly to your grid’s data view:<px:PXLookupMultiSelect ID="edPriceClassID" runat="server" DataField="PriceClassID" CommitChanges="True" DataMember="DiscountDetails" /> - Graph Logic: Add logic to handle selected records and insert them into your grid (avoid duplicates with a quick check):
protected void DiscountDetails_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { var currentDetail = e.Row as DiscountDetail; if (currentDetail == null) return; // Grab all selected Price Classes from the lookup var selectedPriceClasses = edPriceClassID.SelectedRecords.Cast<PriceClass>().ToList(); foreach (var pc in selectedPriceClasses) { // Only add if the Price Class isn't already in the grid if (!DiscountDetails.Select().Any(d => d.PriceClassID == pc.PriceClassID)) { var newDetail = new DiscountDetail { PriceClassID = pc.PriceClassID, // Populate any required fields (like CompanyID for multi-tenant or DiscountID) DiscountID = Base.Document.Current.DiscountID, CompanyID = Base.Accessinfo.CompanyID }; DiscountDetails.Insert(newDetail); } } }
If you prefer to keep the standard lookup dialog but add checkboxes for multi-selection, you can extend the base lookup graph:
- Create a Custom Lookup Graph: Inherit from the base lookup graph (e.g.,
PriceClassMaint) and enable multi-select on the primary data view:public class CustomPriceClassLookup : PriceClassMaint { public PXSelect<PriceClass> PriceClasses; protected override void Initialize() { base.Initialize(); PriceClasses.AllowMultiSelect = true; } } - Link the Custom Lookup to Your Control: Update the
PXLookupcontrol in your screen’s ASPX to use the custom graph:<px:PXLookup ID="edPriceClassID" runat="server" DataField="PriceClassID" LookupGraph="YourNamespace.CustomPriceClassLookup" /> - Handle Selected Records: Add a
LookupReturnevent handler in your main graph to process selections and add them to the grid:protected void edPriceClassID_LookupReturn(PXCache cache, PXLookupReturnEventArgs e) { var selectedItems = e.ReturnValue as IEnumerable<PriceClass>; if (selectedItems == null) return; foreach (var pc in selectedItems) { if (!DiscountDetails.Select().Any(d => d.PriceClassID == pc.PriceClassID)) { var newDetail = new DiscountDetail { PriceClassID = pc.PriceClassID, DiscountID = Base.Document.Current.DiscountID, CompanyID = Base.Accessinfo.CompanyID }; DiscountDetails.Insert(newDetail); } } }
Since you’re targeting the Discount screen, keep in mind that the base DiscountMaint graph already uses the DiscountDetail DAC for Price Class assignments. The LookupMultiSelect approach works especially well here because it directly connects the lookup to the detail data view, minimizing extra code.
Key Considerations
- Always check for duplicate entries before adding records to avoid grid clutter.
- Ensure required fields (like
CompanyIDor parent record IDs) are populated when inserting new rows. - Test in your specific Acumatica version, as control behavior can vary slightly between releases.
内容的提问来源于stack exchange,提问作者Rick

