AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 08.06.2015, 06:25   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
emeadaxsupport: Using X++ to add a control at runtime
Источник: http://blogs.msdn.com/b/axsupport/ar...lds-on-it.aspx
==============

Adding controls at runtime can be a powerful feature of Microsoft Dynamics AX client development. As a developer you may choose to display a control based on business logic and one way to do this can be with X++. I had a recent case where attempting this caused the Financial dimension fields to not work. I thought I would share some of the learning that took place in resolving the issue.

When adding a control to a form at runtime using X++, you have an option of using the controlMethodOverload method. This method allows the developer to provide additional code to overload the methods on the form. However when this is added to a form with Financial dimension fields, your control may work but the Financial dimension fields become unavailable. You cannot click or do anything with them. Using controlMethodOverload is not documented from Microsoft very much but there are numerous articles externally on trying to use it. In some of the examples I have seen it works well.

X++ Example of adding a Button Control at Runtime

I will add a button named DynamicButtonControl to the BankAccountTable form to illustrate the behavior as this form has Financial dimension fields. A new method called addButtonAtRuntime and DynamicButtonControl_Clicked will be created like below:

private void addButtonAtRuntime()
{
FormButtonControl formButtonControl;
formButtonControl = this.design().addControl(FormControlType::Button, "DynamicButtonControl");
formButtonControl.text("Dynamic FormButtonControl button");
this.controlMethodOverload(true);
}




void DynamicButtonControl_Clicked(FormButtonControl _formButtonControl)
{
;
info ("Dynamic button clicked!");
}





Then add the below to the existing init method of the BankAccountTable form:



element.addButtonAtRuntime();





Now you can test the BankAccountTable form and the button should show up in the bottom of the form. You can click this new button and the Infolog window will open. However the Financial dimension fields will not work when clicked on.





The resolution is to use the registerOverrideMethod method to override the specific control we added. This method is available on Form controls. You may not find much detailed documentation from Microsoft on it, but it can be used like this:



formButtonControl.registerOverrideMethod(methodStr(FormButtonControl, clicked),'DynamicButtonControl_Clicked',this);







In the above we know the name of the button control we added was DynamicButtonControl. To override the button clicked event we use the above syntax with the registerOverrideMethod method. Now all the form controls like the Financial dimension fields and the custom button control added at runtime will work correctly. When you add Form controls at runtime, you will probably want to use the registerOverrideMethod method over the controlMethodOverload method.






Источник: http://blogs.msdn.com/b/axsupport/ar...lds-on-it.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 08.06.2015, 11:40   #2  
kashperuk is offline
kashperuk
Участник
Аватар для kashperuk
MCBMSS
Соотечественники
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,361 / 2084 (78) +++++++++
Регистрация: 30.05.2004
Адрес: Atlanta, GA, USA
Или же можно посмотреть на одну из Tutorial_Form* форм, который создают динамически контрольчики.
За это сообщение автора поблагодарили: mazzy (2).
Старый 08.06.2015, 14:44   #3  
MikeR is offline
MikeR
MCT
Аватар для MikeR
MCBMSS
Лучший по профессии 2015
Лучший по профессии 2014
 
1,628 / 627 (24) +++++++
Регистрация: 28.11.2005
Адрес: просто землянин
По моему такие контрольчики на формы listpage не задеплоить и на портале не посмотреть, то есть работает только на клиенте.
__________________
Axapta book for developer
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
emeadaxsupport: What Visual Studio Source Control > Plug-in selection, when using TFS as Dynamics AX 2012 Version Control System? Blog bot DAX Blogs 0 25.03.2015 13:11
Axilicious:Hosting custom WPF calendar control in AX 2012 Blog bot DAX Blogs 0 20.05.2013 18:11
emeadaxsupport: AX for Retail 2012 R2: Adding a Custom User Control to the POS Blog bot DAX Blogs 0 27.02.2013 07:14
Solutions Monkey: 64bit machine - VS EP add-in not deploying user control to SharePoint while saving Blog bot DAX Blogs 0 06.01.2010 08:19
emeadaxsupport: Renaming an AOT object in Dynamics AX 2009 that is under source control with Team Foundation Server Blog bot DAX Blogs 0 06.10.2009 02:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 02:04.