问题
I'd like to enable or disable a button upon selecting a line in a grid, here's what I tried for now :
public virtual void ARRegister_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
ARRegister row = e.Row as ARRegister;
if (row == null) return;
UnProcessLettering.SetEnabled(row.GetExtension<ARRegisterLeExt>().LettrageCD != null);
}
And I've set the syncposition as true in my grid. But nothing changes when I select a row in which LettrageCD is not null or is null.
Edit : it seems my question is a duplicate : Is there any event triggered when highlighting a row? (didnt find it during my first search :( )
回答1:
Instead of calling SetEnabled on the PXAction, use the StateColumn property on your button aspx declaration.
When you declare your button, you specify a Boolean DAC field that will enable/disable the button based on it's value. Note that the button needs the DependOnGrid property set to the ID of the grid to get the selected row:
<px:PXToolBarButton Text="Button A" DependOnGrid="grid" StateColumn="IsButtonVisible">
IsButtonVisible is a custom unbound Boolean DAC field:
#region IsButtonVisible
public abstract class isButtonVisible : IBqlField
{
}
protected bool? _IsButtonVisible;
[PXBool]
[PXUIField(DisplayName = "Is Button Visible", Enabled = false, Visible = false)]
public virtual bool? IsButtonVisible
{
get
{
return _IsButtonVisible;
}
set
{
_IsButtonVisible = value;
}
}
#endregion
You can set the value of IsButtonVisible in the RowSelected event based on your business logic:
protected virtual void DAC_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
DAC row = e.Row as DAC;
if (row != null)
{
bool yourCondition = ???;
row.IsButtonVisible = yourCondition;
}
}
Source: Enable disable button of grid or PXToolBarButton, which depends from value of column in Acumatica
来源:https://stackoverflow.com/questions/49369916/action-upon-selecting-a-line-in-a-grid