Mattersphere Developers Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
avatar
Heather@FootAnstey
Posts : 57
Join date : 2018-12-19

Search List: Edit button - Enable/Disable Empty Search List: Edit button - Enable/Disable

Sat 8 Feb 2020 - 9:57
Original post: GaryC 14/06/2011

"I've added some script on the ItemClick event to enable or disable the search list buttons dependent on a field value. This works fine for the delete button, or any
buttons I've created ,but doesn't function for the standard edit, editwizard or editdialog buttons. Any ideas?

protected override void ItemClick(object sender, FWBS.OMS.UI.Windows.SearchItemHoverEventArgs e) {
if(Convert.ToBoolean(SearchControl.CurrentItem()[“Exported”].Value)== false)
{
SearchControl.GetOMSToolBarButton(“cmdExport”).Enabled = true;
SearchControl.GetOMSToolBarButton(“cmdDelete”).Enabled = true;
SearchControl.GetOMSToolBarButton(“cmdEdit”).Enabled = true;
}
else
{
SearchControl.GetOMSToolBarButton(“cmdExport”).Enabled = false;
SearchControl.GetOMSToolBarButton(“cmdDelete”).Enabled = false;
SearchControl.GetOMSToolBarButton(“cmdEdit”).Enabled = false;
}
}

Edit: I should add that I've managed to get around the problem by using the visible property of the edit button rather than the enable, but ideally I'd like to be able to
use enable/disable."

Responses:

RichardA 14/06/2011

"Hi Gary,
It could be that an exception is being thrown and that your code isn't actually completing. There are some areas in scripting where we will not throw the exceptions so you are better to always wrap your scripting in try catches so you can handle the exception appropriately.
Can you try

FWBS.OMS.UI.Windows.OMSToolBarButton _btn = this.SearchControl.GetOMSToolBarButton(“cmdExport”);
if (_btn != null)
_btn.Enable = true; // false
_btn = this.SearchControl.GetOMSToolBarButton(“cmdDelete”);
if (_btn != null)
_btn.Enable = true; // false
_btn = this.SearchControl.GetOMSToolBarButton(“cmdEdit”);
if (_btn != null)
_btn.Enable = true; // false

Regards Richard"


GaryC

[quote=“RichardA”]
Hi Gary,

It could be that an exception is being thrown and that your code isn't actually completing. There are some areas in scripting where we will not throw the exceptions so

you are better to always wrap your scripting in try catches so you can handle the exception appropriately.

Can you try
FWBS.OMS.UI.Windows.OMSToolBarButton _btn = this.SearchControl.GetOMSToolBarButton(“cmdExport”);
if (_btn != null)
_btn.Enabled = true; // false
_btn = this.SearchControl.GetOMSToolBarButton(“cmdDelete”);
if (_btn != null)
_btn.Enabled = true; // false
_btn = this.SearchControl.GetOMSToolBarButton(“cmdEdit”);
if (_btn != null)
_btn.Enabled = true; // false
Regards
Richard [/quote]

"Thanks for the response Richard,
I wrapped the code above (as amended) in a try and catch. No error was thrown and the functionality was exactly the same as before - it worked for the cmddelete and the cmdexport button but not for the cmdedit.
Interestingly if you click and hold an item the edit button disables but as soon as you release the click the edit button becomes active again. Cheers
Gary"

RichardA 14/06/2011

"It looks like some of our internal code runs after the Item_Click event and re-enables the button.
Each button has a property 'Enabled when multi selected' . If you set it to true then the internal code won't re-enabled that button. You might want to then disable it in your script if multiple rows are selected.
Regards Richard"

GaryC 14/06/2011

"Thanks Richard, that 'Enabled when multi selected' seemed to be the cause. As soon as I enabled it my script functioned as expected. How would you recommend disabling when nulti-selected through script? Something like:

int _counter = 0;
foreach (FWBS.Common.KeyValueCollection sr in SearchControl.SelectedItems)
{
_counter++;
}
if (_counter>1) SearchControl.GetOMSToolBarButton(“cmdEdit”).Enabled = false;

or is there are simpler way?"

RichardA 14/06/2011

"This should do the trick

if (SearchControl.SelectedItems.Length>1) SearchControl.GetOMSToolBarButton(“cmdEdit”).Enabled = false;

"


Back to top
Permissions in this forum:
You cannot reply to topics in this forum