Skip to main content
Answer

Prevent Adding Empty Row in Grid

  • October 20, 2023
  • 1 reply
  • 126 views

Forum|alt.badge.img

Hi All,

In my custom screen has a PXGrid which is empty in the beginning. After I add new record and press the Verify Vendors button (Some validation is added) then another new empty row added to the grid automatically. Can someone help me out to avoid this scenario?

Following is my custom screens and button click event.

  1. Before the click event
  1.  After the click event
  2. Button click event 

    public PXAction<HMRCVendorRegisterDetail> VerifyVendors;
            [PXButton(CommitChanges = true)]
            [PXUIField(DisplayName = "Verify Vendors", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = false)]
            protected virtual IEnumerable verifyVendors(PXAdapter adapter)
            {            
                foreach (HMRCVendorRegisterDetail vendorRegisterDetail in VendorRegisterDetail.Select())
                {                
                    if(vendorRegisterDetail.UsrSelect == false)
                    {
                        VendorRegisterDetail.Cache.RaiseExceptionHandling<HMRCVendorRegisterDetail.bAccountID>(vendorRegisterDetail, null, new PXSetPropertyException(Messages.VendorEmptyMessage));
                    }
                    else
                    {
                        //Logic
                    }                   
                    
                }

                return adapter.Get();
            } 

Best answer by darylbowman

I don’t see anything wrong with your code.

You could try this, but I’m not certain anything different is actually happening:

public PXAction<HMRCVendorRegisterDetail> VerifyVendors;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Verify Vendors", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = false)]
protected virtual IEnumerable verifyVendors(PXAdapter adapter)
{
var vendorRegisterGraph = adapter.View.Graph as [graphtype]
foreach (HMRCVendorRegisterDetail vendorRegisterDetail in vendorRegisterGraph.VendorRegisterDetail.Select())
{
if(vendorRegisterDetail.UsrSelect == false)
{
vendorRegisterGraph.VendorRegisterDetail.Cache.RaiseExceptionHandling<HMRCVendorRegisterDetail.bAccountID>(vendorRegisterDetail, null, new PXSetPropertyException(Messages.VendorEmptyMessage));
}
else
{
//Logic
}
}

return adapter.Get();
}

(notice the [graphtype] placeholder where you’ll need to insert the name of your graph)

1 reply

darylbowman
Captain II
Forum|alt.badge.img+15
  • Answer
  • October 20, 2023

I don’t see anything wrong with your code.

You could try this, but I’m not certain anything different is actually happening:

public PXAction<HMRCVendorRegisterDetail> VerifyVendors;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Verify Vendors", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = false)]
protected virtual IEnumerable verifyVendors(PXAdapter adapter)
{
var vendorRegisterGraph = adapter.View.Graph as [graphtype]
foreach (HMRCVendorRegisterDetail vendorRegisterDetail in vendorRegisterGraph.VendorRegisterDetail.Select())
{
if(vendorRegisterDetail.UsrSelect == false)
{
vendorRegisterGraph.VendorRegisterDetail.Cache.RaiseExceptionHandling<HMRCVendorRegisterDetail.bAccountID>(vendorRegisterDetail, null, new PXSetPropertyException(Messages.VendorEmptyMessage));
}
else
{
//Logic
}
}

return adapter.Get();
}

(notice the [graphtype] placeholder where you’ll need to insert the name of your graph)