Skip to main content
Solved

Add to grid only one row

  • October 25, 2026
  • 2 replies
  • 37 views
  • Translate All

Forum|alt.badge.img+2

How to enable add to grid only one row for some conditions ?

Best answer by Dipak Nilkanth

Hi ​@bihalivan15,

You can handle this in the graph code by controlling the detail view’s AllowInsert property and validating the condition in the detail DAC’s RowInserting event.

For example,

1. Disable the Add Row (+) button

In the parent DAC’s RowSelected event, check whether a detail record already exists.

protected virtual void _(Events.RowSelected<MyHeader> e)
{
if (e.Row == null)
return;

MyDetail row = Details.SelectWindowed(0, 1);

Details.Cache.AllowInsert = row == null;
}

Here, Details is the detail view in the graph. If a detail record exists, insertion is disabled, so users cannot add another row through the grid.

2. Enforce the rule in RowInserting

Disabling the button only controls the UI. To enforce the rule at the graph level, validate the insertion as well.

protected virtual void _(Events.RowInserting<MyDetail> e)
{
if (e.Row == null)
return;

MyDetail existingRow = Details.SelectWindowed(0, 1);

if (existingRow != null)
{
e.Cancel = true;

throw new PXException(
"Only one detail row is allowed per document.");
}
}

Replace MyHeader,  MyDetail, and Details view with your actual DACs and view.  If the rule depends on a specific business condition, apply that condition consistently in both events.

Hope, it helps!

View original

2 replies

Forum|alt.badge.img

Hii, ​@bihalivan15,

Acumatica has no grid property that limits a grid to one row. You limit it in the graph code, at two levels:

  1. UI level: in the RowSelected event of the header (parent) DAC, set AllowInsert = false on the detail view. Do this when the condition is true and one row already exists. The grid’s Add Row (+) button is then disabled.
  2. Server level: in the RowInserting event of the detail DAC, cancel the insert and show an error if a row already exists. This also stops extra rows coming from the Web API, Import Scenarios, Copy/Paste, or code.
Translate

Dipak Nilkanth
Pro III
Forum|alt.badge.img+14

Hi ​@bihalivan15,

You can handle this in the graph code by controlling the detail view’s AllowInsert property and validating the condition in the detail DAC’s RowInserting event.

For example,

1. Disable the Add Row (+) button

In the parent DAC’s RowSelected event, check whether a detail record already exists.

protected virtual void _(Events.RowSelected<MyHeader> e)
{
if (e.Row == null)
return;

MyDetail row = Details.SelectWindowed(0, 1);

Details.Cache.AllowInsert = row == null;
}

Here, Details is the detail view in the graph. If a detail record exists, insertion is disabled, so users cannot add another row through the grid.

2. Enforce the rule in RowInserting

Disabling the button only controls the UI. To enforce the rule at the graph level, validate the insertion as well.

protected virtual void _(Events.RowInserting<MyDetail> e)
{
if (e.Row == null)
return;

MyDetail existingRow = Details.SelectWindowed(0, 1);

if (existingRow != null)
{
e.Cancel = true;

throw new PXException(
"Only one detail row is allowed per document.");
}
}

Replace MyHeader,  MyDetail, and Details view with your actual DACs and view.  If the rule depends on a specific business condition, apply that condition consistently in both events.

Hope, it helps!

Translate